Anuj Varma Software • Cloud • Security • AI

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.

Anuj holds professional certifications in Google Cloud, AWS as well as certifications in Docker and App Performance Tools such as New Relic. He specializes in Cloud Security, Data Encryption and Container Technologies.

Initial Consultation

Anuj Varma – who has written posts on Anuj Varma.


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.