Created
April 19, 2012 06:31
-
-
Save hatelove/2419122 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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