Share via


My linq query converted to IList. How to query?

Question

Tuesday, February 3, 2015 4:45 AM

Hi I have a ling query which I need to filter  several time based on a name value.

Resharper warns that of "multiple enumeration of ienumerable". This is suppose to be inefficient.

It converted it to this:

var query= myQueryS as IList ?? myQuery.ToList();

Question is what is "query" now and how do you actually get the results you need from it?

Thanks.

All replies (5)

Tuesday, February 3, 2015 7:24 AM âś…Answered

Chances are whatever myQueryS is can be converted to IList which is non-generic, and the methods like Select work on the generic IList<T>

Just use

var query= myQuery.ToList();

that will ensure query is List<T>


Tuesday, February 3, 2015 5:42 AM

Hover over "var" in Visual Studio and the pop-up will tell you what query is.  If myQueryS is IEnumerable<T> then query will be List<T>.  You get results from it the same way you do IEnumerable.  It would help if you posted some of the relevant code.


Tuesday, February 3, 2015 6:20 AM

When I hover over it I see the list of results, lots of rows.

But it does not allow me to do a .select on it?


Tuesday, February 3, 2015 6:56 AM

Do you have

using System.Linq;

at the top of your code file?


Tuesday, February 3, 2015 7:15 AM

Yep got that