© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
11 replies
thirteenbinary

❔ 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:
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);
    }
}
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);
    }
}

So the question comes.
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

What is the use of Interface
C#CC# / help
16mo ago
✅ Purpose and use of nameof() keyword
C#CC# / help
12mo ago
❔ What of use is the identifier for the delegate?
C#CC# / help
3y ago
✅ readonly keyword vs const keyword and use-case
C#CC# / help
12mo ago