Skip to content

Instantly share code, notes, and snippets.

@hatelove
Created April 19, 2012 06:31
Show Gist options
  • Save hatelove/2419122 to your computer and use it in GitHub Desktop.
Save hatelove/2419122 to your computer and use it in GitHub Desktop.
class Program
{
static void Main(string[] args)
{
var list = new List<Customer>();
list.Add(new Customer() { Name = "jordan", Age = 19 });
list.Add(new Customer() { Name = "小章", Age = 20 });
list.Add(new Customer() { Name = "盧克", Age = 34 });
list.Add(new Customer() { Name = "9gy", Age = 29 });
list.Add(new Customer() { Name = "小盧克", Age = 17 });
var result = list.GetIndex(x => x.Age == 34);
Console.WriteLine(result);
}
}
public static class JoeyExtension
{
public static int GetIndex<TSource>(this IEnumerable<TSource> source, Predicate<TSource> predicate)
{
var result = source.ToList<TSource>().FindIndex(predicate);
return result;
}
}
internal class Customer
{
public string Name { get; set; }
public int Age { get; set; }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment