B
Bob Rock
Why doesn't this code compile???
Why can I call Invoke on .NET Framework defined delegates and not on
my own.
using System;
namespace DelegatesTest
{
public delegate void MyDelegate();
class MyClass
{
// .NET Framework defined delegates
public System.Threading.TimerCallback timerCallback = null;
public System.Timers.ElapsedEventHandler elapsedEventHandler = null;
// my own delegate
public DelegatesTest.MyDelegate myDelegate = null;
static void Main(string[] args)
{
MyClass myClass = new MyClass();
// OK
myClass.timerCallback.Invoke(null);
// OK
myClass.elapsedEventHandler.Invoke(null, null);
// NOT OK - will not compile
myClass.myDelegate.Invoke();
}
}
}
Don't look at the fact that the 3 delegates are not assigned any valid
method ... I tried writing the shortest possible example to explain my
problem.
Bob
Why can I call Invoke on .NET Framework defined delegates and not on
my own.
using System;
namespace DelegatesTest
{
public delegate void MyDelegate();
class MyClass
{
// .NET Framework defined delegates
public System.Threading.TimerCallback timerCallback = null;
public System.Timers.ElapsedEventHandler elapsedEventHandler = null;
// my own delegate
public DelegatesTest.MyDelegate myDelegate = null;
static void Main(string[] args)
{
MyClass myClass = new MyClass();
// OK
myClass.timerCallback.Invoke(null);
// OK
myClass.elapsedEventHandler.Invoke(null, null);
// NOT OK - will not compile
myClass.myDelegate.Invoke();
}
}
}
Don't look at the fact that the 3 delegates are not assigned any valid
method ... I tried writing the shortest possible example to explain my
problem.
Bob