static void Main()
{
string[] a = { "a", "asd", "bdfsd", "we" };
a = a.OrderBy(fun).ToArray();
}
private static int fun(string s)
{
return s.Length;
}
its is giving compile time error . I know that we can do this with Lambda expression like this. a.OrderBy(s=>s.Length).ToArray(); but i want to this do by defining different function . What mistake i have done?
The expression
funis an untyped expression called a method group.Since a method group has no type, the compiler cannot infer the type parameters of the generic
OrderBymethod.You need to explicitly pass the type parameters, like this:
Or,