Linq in C# - Change type -
why (and how) change type of 'b' b 'system.linq.enumerable.whereenumerableiterator' 'system.collections.generic.list'
list<int> = new list<int>{ 45, 78, 45, 12, 4, 78, 54 }; var b = a.select (n => n +12).where (n => n>50); //enumerable.whereenumerableiterator<int> b = b.tolist (); // system.collections.generic.list<int>
why change type of b? possible change type in c#? example, possible create 'string' , change 'int' 'char'? of course, not. why changed type of code?
.where<t>()
returns ienumerable<t>
. enumerable.whereenumerableiterator<t>
concrete class enumerable.where
uses implement interface. shouldn't reference in code since it's implementation detail , subject change.
.tolist()
takes ienumerable<t>
, creates concrete list<t>
. not "change type" mention in question - creates new object. how implementation detail shouldn't need worry about.
you can browse .net reference source @ implementation of where
, tolist
Comments
Post a Comment