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; }
    }
View Code

相关文章:

  • 2022-12-23
  • 2021-09-03
  • 2021-07-16
  • 2022-01-07
  • 2021-11-03
  • 2022-01-07
猜你喜欢
  • 2022-12-23
  • 2021-09-02
  • 2022-02-15
  • 2021-12-25
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案