Check that value exists in a Generic List of Values

前端 未结 2 1939
终归单人心
终归单人心 2020-12-19 13:14

I am trying to figure out how to check if testInt exists in all Car.SomeID in List

So:

int testInt = 10;
List myCars = GetCars();
<         


        
相关标签:
2条回答
  • 2020-12-19 13:41
    myCars.Exists(c => c.SomeID == 10);
    
    0 讨论(0)
  • 2020-12-19 13:44

    In the more general case, with LINQ (supports any type of abstract typed list):

    bool hasCar = myCars.Any(c => c.SomeID == testInt);
    
    0 讨论(0)
提交回复
热议问题