c# - Is there a penalty for Enumerable.ToList() -


an enumerable not let access elements index anenumerable[i]. list - alist[i]. therefore list provides feature compared enumerable.

when perform .tolist() convert enumerable list, operation done in constant time or need traverse enumerable able convert list?

time has @ least o(n), since code doing this:

public static ilist<t> tolist(this ienumerable<t> e) {     list<t> list = new list<t>();     foreach (t elem in e) list.add(elem);     return list; } 

since have list.count calls add, there's cost.

i should point out there code in more general case things like

if (e ilist<t>) return (ilist<t>)e; 

Comments

Popular posts from this blog

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -