L
Luke
class TestNoEventKeyword
{
public static void Test()
{
Student s1=new Student();
Student s2=new Student();
s1.RegisterOK +=new
Student.DelegateRegisterOkEvent(Student_RegisterOK);
s2.RegisterOK +=new
Student.DelegateRegisterOkEvent(Student_RegisterOK);
s1.Register();
s2.Register();
Console.ReadLine();
}
static void Student_RegisterOK()
{
Console.WriteLine("Hello");
}
}
class Student
{
public delegate void DelegateRegisterOkEvent
();
public event DelegateRegisterOkEvent
RegisterOK;
public string Name;
public void Register()
{
Console.WriteLine("Register Method");
RegisterOK();
}
}
When calling TestNoEventKeyword.Test(); in Main
(), it will output:
Register Method
Hello
Register Method
Hello
QUESTION: how if we remove the modifier event for
RegisterOK? The output is just the same.
As I understand, delegate is like defing a function
pointer via typedef in C++, and the so-called event
RegisterOK is a function pointer; Student_RegisterOK is
the underlying function attached to the pointer. What is
the difference if not use event for RegisterOK? (without
regard to event-accessors)
{
public static void Test()
{
Student s1=new Student();
Student s2=new Student();
s1.RegisterOK +=new
Student.DelegateRegisterOkEvent(Student_RegisterOK);
s2.RegisterOK +=new
Student.DelegateRegisterOkEvent(Student_RegisterOK);
s1.Register();
s2.Register();
Console.ReadLine();
}
static void Student_RegisterOK()
{
Console.WriteLine("Hello");
}
}
class Student
{
public delegate void DelegateRegisterOkEvent
();
public event DelegateRegisterOkEvent
RegisterOK;
public string Name;
public void Register()
{
Console.WriteLine("Register Method");
RegisterOK();
}
}
When calling TestNoEventKeyword.Test(); in Main
(), it will output:
Register Method
Hello
Register Method
Hello
QUESTION: how if we remove the modifier event for
RegisterOK? The output is just the same.
As I understand, delegate is like defing a function
pointer via typedef in C++, and the so-called event
RegisterOK is a function pointer; Student_RegisterOK is
the underlying function attached to the pointer. What is
the difference if not use event for RegisterOK? (without
regard to event-accessors)