Converting a normal collection to IEnumerable
Suppose you are stuck with a namevaluecollection – it is not of type IQueryable or IEnumerable. So – none of your LINQ queries will work on it.
Convert it to IEnumerable<T>
IEnumerable<string> canBeQueried = nvc.OfType<string>();
// To convert it to a string array
string[] myArr = canBeQueried.Cast<String>().ToArray();
Convert it to IQueryable<T>
IQueryable queryable = nvc.AsQueryable();
Summary – Once you have these converted to either an IQueryable or an IEnumerable, you can execute your normal LINQ queries against them.
Leave a Reply