In condition using LINQ

后端 未结 2 831
囚心锁ツ
囚心锁ツ 2021-01-22 07:07

OK, another LINQ question. How do I do an \"IN\" condition using LINQ. I have an IEnumerable list of myObject and want to do something like myObject.Description in(\'Help\',

2条回答
  •  梦毁少年i
    2021-01-22 08:00

    Use Contains on a collection:

    string[] descriptions = { "Help", "Admin", "Docs" };
    
    var query = from foo in list
                where descriptions.Contains(foo.Description)
                select ...;
    

    (For larger collections, a HashSet might be better.)

提交回复
热议问题