Thursday, January 19, 2012

What is a Method Group?

A method group is the name for a set of methods (that might be just one).
The ToString function has many overloads - the method group would be the group consisting of all the different overloads for that function.
It is a compiler term for "I know what the method name is, but I don't know the signature"; it has no existence at runtime, where it is converted in the correct overload.
Also, if you are using LINQ, you can apparently do something like myList.Select(methodGroup).
so you can replace this code:
private static int[] ParseInt(string s)
{
    var t = ParseString(s);
    var i = t.Select(x => int.Parse(x));
    return i.ToArray();
}
with this one:
private static int[] ParseInt(string s)
{
    var t = ParseString(s);
    var i = t.Select(int.Parse);
    return i.ToArray();
}

Submit this story to DotNetKicks