❔ What of use is the keyword "event"
The essence of the event field is just an object of delegate type which will invoke embedded methods when it is invoked like a method, coding below is also ok:
So the question comes.
So the question comes.
c#
using System;
class A
{
public delegate void F(int x, int y);
static public /*Event*/ F Event;
public static void Hi()
{
Event(1, 2);
}
}
class B
{
internal void Print(int x,int y)
{
Console.WriteLine(x + y);
}
}
public class Test
{
static void Main()
{
B suck = new B();
A.Event += suck.Print;
A.F x = new A.F(suck.Print);
A.Hi();
x(1, 2);
}
}