LINQ where or filter c#

后端 未结 5 1343
故里飘歌
故里飘歌 2021-01-24 04:29

I have a collection being returned by a web service. A property of this collection is \"StatusCode\" which is a string value that can be anywhere from 0 to 5 (don\'t ask me why

5条回答
  •  春和景丽
    2021-01-24 04:34

    You could define an IsIn() generic Extension Method:

    public static bool IsIn(this T value, params T[] values)
    {
        return values.Contains(value);
    }
    

    Then you could write your query like this:

    var wo = from q in workOrders where w.IsIn("1","2","3") select w;
    

提交回复
热议问题