I’ve got really simple code:
static void Main(string[] args)
{
var task = Task.Factory.StartNew(GetInt);
var task2 = Task.Factory.StartNew(
() =>
{
return GetInt();
});
}
static int GetInt()
{
return 64;
}
Why do I get a compiler error for the first task?
The method signatures (no params, return type is int) are equal, aren’t they?
I know a solution(which is quite simple: var task = Task.Factory.StartNew<int>(GetInt);) but I’d like to know whats the problem with the code above.
You get an ambiguous call error because the method signature is the same.
Return values are not part of the signature.
Since you don’t provide an explicit return type, the compiler doesn’t know which to take.
Method Signature in C#