c# - How to pick IEnumerable<T> instead of List<T> from an ICollection<T>? -


i have following lines work supposed to.

dictionary<guid, list<t>> dictionary = source.todictionary(   element => element.id,   element => element.ts.tolist()); 

however, i'd first line use ienumerable, creates error of type mismatch.

dictionary<guid, ienumerable<t>> dictionary = source.todictionary( ... ); 

using toarray instead of tolist won't me (getting same error, plus i've learned not use arrays in c# unless really, required) , far can tell, type of ts icollection.

is possible convert whole shabang way wish without going hardcore , using casting?

if want avoid casting, can use asenumerable extension method, return correct type, hide original instance/implementation behind anonymous enumerable.

i use element => element.ts ienumerable<t> though, avoid calling method satisfy limited generics inference.


Comments