Prathyush Prathyush - 2 months ago 5x
C# Question

Array fo String to Use with IN CLAUSE in LINQ

I would like to use string array in linq query with IN CLAUSE like below

string[] strArray = {"A", "B", "C", "D"};
foreach (var item in SomeCollection.Where(x => x.column.Contains(seriesIIType)))


But I am getting below error.

Error 1 The best overloaded method match for 'string.Contains(string)'
has some invalid arguments Error 2 Argument 1: cannot convert from
'string[]' to 'string'


Call the Contains method on your array.

string[] strArray = {"A", "B", "C", "D"};
SomeCollection.Where(x => strArray.Contains(x.column))

This will return those items which has column property value is either one of those in the array.

Assuming column property is of same type as your array (string)