S
Scott M.
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 myEventEventHandler();
public event myEventEventHandler myEvent;
public void ChangeSpeed(short 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.Collections;
using System.Data;
using System.Diagnostics;
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.EventHandler' to
'foo.fooFoo.myEventEventHandler'
x.myEvent += new System.EventHandler(x_myEvent);
}
private static void x_myEvent(object sender, System.EventArgs e)
{
Console.WriteLine("");
}
}
}
Thanks for your help!
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 myEventEventHandler();
public event myEventEventHandler myEvent;
public void ChangeSpeed(short 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.Collections;
using System.Data;
using System.Diagnostics;
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.EventHandler' to
'foo.fooFoo.myEventEventHandler'
x.myEvent += new System.EventHandler(x_myEvent);
}
private static void x_myEvent(object sender, System.EventArgs e)
{
Console.WriteLine("");
}
}
}
Thanks for your help!