I have a class that implements IEnumerable, but doesn’t implement IEnumerable<T>. I can’t change this class, and I can’t use another class instead of it. As I’ve understood from MSDN LINQ can be used if class implements IEnumerable<T>. I’ve tried using instance.ToQueryable(), but it still doesn’t enable LINQ methods. I know for sure that this class can contain instances of only one type, so the class could implement IEnumerable<T>, but it just doesn’t. So what can I do to query this class using LINQ expressions?
I have a class that implements IEnumerable , but doesn’t implement IEnumerable<T> . I
Share
You can use
Cast<T>()orOfType<T>to get a generic version of an IEnumerable that fully supports LINQ.Eg.
Or if you don’t know what type it contains you can always do:
If your non-generic
IEnumerablecontains objects of various types and you are only interested in eg. the strings you can do: