i use lots of extension methods like .ToList() and .Reverse() etc without really thinking about what really happens under the covers when i use them. I’ve been searching on google to find out what exactly these methods do, but i can’t seem to find them anywhere. When i use a .toList() in visual studio and i click on “Go to definition” all i see is
// Summary:
// Creates a System.Collections.Generic.List<T> from an System.Collections.Generic.IEnumerable<T>.
//
// Parameters:
// source:
// The System.Collections.Generic.IEnumerable<T> to create a System.Collections.Generic.List<T>
// from.
//
...etc
im trying to find out what’s going on inside the (for instance) .Reverse(); method. Does it use a stack, does it simply do something like this … ?
public static List<string> Reverse(List<string> oldList)
{
List<string> newList = new List<string>();
for (int i = oldList.Count-1; i >= 0; i --)
{
newList.Add(oldList[i]);
}
return newList;
}
Note: i can’t imagine it’d actually be something like this, but just to clarify my question.
Is there any site/book/whatever that i can check out that shows what exactly these methods do ?
You can configure Visual Studio to load the source code of .Net Framework from Microsoft source servers, when you click ‘Go to Definition’. Here are some instructions: http://referencesource.microsoft.com/downloadsetup.aspx
Note that you don’t have to download the big package, just setting up the options is enough.
Here is the source code of
ToList:And here is the source code of
Reverse: