Searching if value exists in a list of objects using Linq

后端 未结 9 1662
执念已碎
执念已碎 2020-12-04 05:17

Say I have a class Customer which has a property FirstName. Then I have a List.

Can LINQ be used to find if th

9条回答
  •  既然无缘
    2020-12-04 05:42

    List list = ...;
    Customer john = list.SingleOrDefault(customer => customer.Firstname == "John");
    

    john will be null if no customer exists with a first name of "John".

提交回复
热议问题