Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 163527
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T11:34:59+00:00 2026-05-11T11:34:59+00:00

How can I make my own event in C#?

  • 0

How can I make my own event in C#?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T11:34:59+00:00Added an answer on May 11, 2026 at 11:34 am

    Here’s an example of creating and using an event with C#

    using System;  namespace Event_Example {     //First we have to define a delegate that acts as a signature for the     //function that is ultimately called when the event is triggered.     //You will notice that the second parameter is of MyEventArgs type.     //This object will contain information about the triggered event.     public delegate void MyEventHandler(object source, MyEventArgs e);      //This is a class which describes the event to the class that recieves it.     //An EventArgs class must always derive from System.EventArgs.     public class MyEventArgs : EventArgs     {         private string EventInfo;         public MyEventArgs(string Text)         {             EventInfo = Text;         }         public string GetInfo()         {             return EventInfo;         }     }      //This next class is the one which contains an event and triggers it     //once an action is performed. For example, lets trigger this event     //once a variable is incremented over a particular value. Notice the     //event uses the MyEventHandler delegate to create a signature     //for the called function.     public class MyClass     {         public event MyEventHandler OnMaximum;         private int i;         private int Maximum = 10;         public int MyValue         {             get             {                 return i;             }             set             {                 if(value <= Maximum)                 {                     i = value;                 }                 else                 {                     //To make sure we only trigger the event if a handler is present                     //we check the event to make sure it's not null.                     if(OnMaximum != null)                     {                         OnMaximum(this, new MyEventArgs('You've entered ' +                             value.ToString() +                             ', but the maximum is ' +                             Maximum.ToString()));                     }                 }             }         }     }      class Program     {         //This is the actual method that will be assigned to the event handler         //within the above class. This is where we perform an action once the         //event has been triggered.         static void MaximumReached(object source, MyEventArgs e)         {             Console.WriteLine(e.GetInfo());         }          static void Main(string[] args)         {             //Now lets test the event contained in the above class.             MyClass MyObject = new MyClass();             MyObject.OnMaximum += new MyEventHandler(MaximumReached);              for(int x = 0; x <= 15; x++)             {                 MyObject.MyValue = x;             }              Console.ReadLine();         }     } } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 131k
  • Answers 131k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer myCallback = function(li, $input) { // I need to refer… May 12, 2026 at 6:12 am
  • Editorial Team
    Editorial Team added an answer The StringDictionary type is rather obsolete. I think that Dictionary<String,String>… May 12, 2026 at 6:12 am
  • Editorial Team
    Editorial Team added an answer Regular expressions: var numberPattern = /\d+/g; 'something102asdfkj1948948'.match( numberPattern ) This… May 12, 2026 at 6:12 am

Related Questions

For making a scalable multiuser server in C#, which of these two types of
Im getting frustrated because of OpenDNS and other services (ie: roadrunner) that now always
I have this garden variety USB video camera, and it came with two mini-apps,
I have to interface with a slightly archaic system that doesn't use webservices. In

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.