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

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -