ILearnable .Net

March 10, 2010

ToList() on a list

Filed under: Uncategorized — andreakn @ 09:47

I usually add this little gem in my projects:

public static List<T> ToList<T>(this List<T> list)
{
return list;
}

so that calling ToList on something that is already a list doesn’t require looping through all the content (which is the default implementation of IEnumerable[t].ToList())

I also tend to put it into the System.Linq namespace so that it comes automatically when I get the original method. (i know it’s not the recommended way, but GOD it’s so practical)

premature optimization is the root of all evil, but small invisible ones isn’t (imho)

Advertisements

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: