Linq Where condition to match array
asp.net-mvc, c#, lambda, linq
Solution
You can check if an array contains some item using the Array.IndexOf<T> Method:
bool strarrayContainsX = Array.IndexOf<string>(strarray, "X") >= 0;
However, I'd recommend you use a HashSet<string> instead of a string array for anything more than a few items. The HashSet<T> Class provides a Contains Method to check if a set contains some item:
HashSet<string> strset = new HashSet<string>(strarray);
bool strsetContainsX = strset.Contains("X");
The resulting query then looks like this:
var k = objlist.Where(u => strset.Contains(u.somecol)).ToList();
Problem
I have a linq list obtained from database in my Model. Now I have a string array obtained from my controller. I want to construct a statement pseudo-code ``` List<object> objlist = db.objects.tolist(); string[] strarray; // obtained from a long code. var k = objlist.Where(u => u.somecol == strarray[0] || u.somecol == strarray[1]........strarray[n]).toList(); ``` I am little bit confused how to accomplish this since my `strarray[]` is variable length and can contain upto 1000 words.