Why Invoke() works on .NET framework delegates and not on my own????
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();
///
/// Summary description for MyClass.
///
class MyClass
{
public System.Threading.TimerCallback timerCallback = null;
public System.Timers.ElapsedEventHandler elapsedEventHandler = null;
public DelegatesTest.MyDelegate myDelegate = null;
///
/// The main entry point for the application.
///
[STAThread]
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