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

  • SEARCH
  • Home
  • 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 6693399
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:58:42+00:00 2026-05-26T05:58:42+00:00

I am learning Events and Delegates & started with multiple events now. Just that

  • 0

I am learning Events and Delegates & started with multiple events now. Just that the docs does not supply any information or code example to raising events defined in this manner.Below you can find a simple example

Sample Code

public class Person
    {
        private string _name;
        private string _phone;

        public string Name
        {
            get { return _name; }
            set
            {
                _name = value;
            }
        }

        public string Phone
        {
            get { return _phone; }
            set
            {
                _phone = value;
            }
        }

        protected EventHandlerList EventDelegateCollection = new EventHandlerList();

        //define the event key
        static readonly object PhoneChangedEventKey = new object();
        public event EventHandler PhoneChanged
        {
            add
            {
                EventDelegateCollection.AddHandler(PhoneChangedEventKey, value);
            }
            remove
            {
                EventDelegateCollection.RemoveHandler(PhoneChangedEventKey, value);
            }
        }
    }

I would like to raise the event when the Phone number is set. if anything sounds funky and don’t understand what i am talking about see here

Update

I would like to clear some doubts here. There are Two ways you can actually subscribe and invoke the event handlers the classical pattern(as described here) where the steps are

  • Define the delegate that acts as signature for subscribed methods.
  • Define the Event that delegates
  • Define the method that raises the handlers
    note: above method creates field for every event hence consumes more memory reference

Event Property is another way where you do below

  • Define a object that acts as Key to a event
  • Define a method to add and remove handlers for the event from the event invocation list
  • Raise the event by determining event handlers based on event key
  • 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. Editorial Team
    Editorial Team
    2026-05-26T05:58:43+00:00Added an answer on May 26, 2026 at 5:58 am

    This is how you should actually raise it

    Code

    public class Person
    {
        private string _name;
        private string _phone;
    
        public string Name
        {
            get { return _name; }
            set
            {
                _name = value;
            }
        }
    
        public string Phone
        {
            get { return _phone; }
            set
            {
                _phone = value;
                //Invoke the Handlers now
                OnPhoneChanged();
            }
        }
    
        protected EventHandlerList EventDelegateCollection = new EventHandlerList();
        static readonly object PhoneChangedEventKey = new object();
        public event EventHandler PhoneChanged
        {
            add
            {
                EventDelegateCollection.AddHandler(PhoneChangedEventKey, value);
            }
            remove
            {
                EventDelegateCollection.RemoveHandler(PhoneChangedEventKey, value);
            }
        }
    
        private void OnPhoneChanged()
        {
            EventHandler subscribedDelegates = (EventHandler)this.EventDelegateCollection[PhoneChangedEventKey];
            subscribedDelegates(this, EventArgs.Empty);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am learning about events in C#. I found out that they are just
I'm just started doing 'hands-on' learning of Actionscript 3 using FlashDevelop. I've now managed
Whilst learning events and delegates I can't help but think about the Observer design
I'm learning events in C# and understand that the EventArgs class carries data about
I've just recently started looking into the details of which events fire when in
hai. I have been learning jS lately. How do i bind multiple events to
I'm learning about Events / Delegates in C#. Could I ask your opinion on
I've just started learning Obj-C. As an alternative to the usual maths examples, I
I'm currently trying learning Cocoa and I am not sure if I understand that
I just started learning php last week and I am trying to populate values

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.