Home > DeveloperSection > Forums > Events in C#
Ankit Singh

Total Post:341

Posted on    December-21-2015 10:17 PM

 C# C#  .NET 

 1 Reply(s)
 185  View(s)
Rate this:
I want to use Events in C# How to use this.

aditya kumar Patel

Total Post:250

Posted on    December-21-2015 10:19 PM

An event can have many handlers. With the event handler syntax, we create a notification system. We attach additional methods without changing other parts of the code. This makes programs easier to maintain.

using System;
namespace EventsInCSharp
    public class OurClass
        public delegate void OurDelegate(string message);
        public event OurDelegate OurEvent;

        public void UseEvent(string message)
            if (OurEvent != null)
    class Program
        static void Main(string[] args)
            OurClass OurClass = new OurClass();
            OurClass.OurEvent += new OurClass.OurDelegate(OurClass_MyEvent);

            Console.WriteLine("Please enter your name\n");
            string msg = Console.ReadLine();
            goto GetReStart;
        static void OurClass_MyEvent(string message)
            Console.WriteLine("Your Name is: {0}", message);


Don't want to miss updates? Please click the below button!

Follow MindStick