class Program { static void Main(string[] args) { List<Person> persons = new List<Person>() { new Person{ID=101,Name="lin1"}, new Person{ID=102,Name="lin2"}, new Person{ID=103,Name="lin3"} }; Person person = persons.Find( delegate(Person p) //this is an anonymous method. { return p.ID == 101; } ); Person p1 = persons.Find(p=>p.ID==101);//using lambda expression Person p2 = persons.Find((Person p)=>p.ID==101);//you can also explicitly the input type but no required Console.WriteLine("person id={0},name={1}", person.ID, person.Name); } } class Person { public int ID { get; set; } public string Name { get; set; } }
相关文章: