I was reading Jon Skeet's answer here
and one of his samples was :
static void Main()
{
int x = 0;
Foo( delegate { return x; } );
}
static void Foo(Func<int, int> action)
{
Console.WriteLine("I suspect the anonymous method...");
}
But how Foo(Func<int, int>)
can deal with delegate { return x; }
which is Func<int>
?
As a matter of fact also Func< int,int,int,int,...>
can deal with delegate { return x; }
...
question 1 Any explanation for this behavior please ?
question 2
I have this code :
class MyClass
{
public delegate void MyEventHandler(object sender);
public event MyEventHandler MyEvent;
}
and I wanted to use generic handlers so :
class MyClass
{
public Action<object> MyEventHandler;
public event MyEventHandler MyEvent;
}
but I get this error :
'UserQuery.MyClass.MyEventHandler(object)' is a 'method' but is used like a 'type'
Why isn't it recognizing it ?