I need a little help please...
I'm simply trying to set up a very basic event for a class and then create
an event handler for that class in a Console application.
I think I'm very close, but I'm missing something. Here's what I've got...
//Abbreviated class code
using System;
namespace foo
{
public class fooFoo
{
public delegate void myEventEventHan dler();
public event myEventEventHan dler myEvent;
public void ChangeSpeed(sho rt ByHowMuch)
{
if (test that determines if the event should be raised)
{
myEvent();
}
}
}
}
// *************** *************** *************** ****
//Console application that has reference to above class's assembly...
using System;
using System.Collecti ons;
using System.Data;
using System.Diagnost ics;
using foo;
namespace TestClass
{
internal sealed class Module1
{
// >--- An "Aside" question here ---<
//Why does the compiler force me to declare the following instance
as static?
//Is it because the class is "internal sealed"?
static fooFoo x = new fooFoo();
public static void Main()
{
//The following line is what won't compile...
//I get the following error message:
//Cannot implicitly convert type 'System.EventHa ndler' to
'foo.fooFoo.myE ventEventHandle r'
x.myEvent += new System.EventHan dler(x_myEvent) ;
}
private static void x_myEvent(objec t sender, System.EventArg s e)
{
Console.WriteLi ne("");
}
}
}
Thanks for your help!