Why doesn't this C# typecheck? In this example, I am trying to pass a method of type string -> string
as a Func<string, string>
. It would be seem perfectly reasonable to be able to omit lambda syntax when passing just the name of an appropriately typed function.
using System;
using System.Linq;
class WeakInference
{
public static void Main (string [] args)
{
// doesn't typecheck
var hellos = args.Select (AppendHello);
// have to do this:
// var hellos = args.Select (s => AppendHello (s));
}
static string AppendHello (string s)
{
return s + "hello";
}
}