Searching if value exists in a list of objects using Linq

后端 未结 9 1666
执念已碎
执念已碎 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:56

    The technique i used before discovering .Any():

    var hasJohn = (from customer in list
          where customer.FirstName == "John"
          select customer).FirstOrDefault() != null;
    

提交回复
热议问题