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 774603
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T19:09:27+00:00 2026-05-14T19:09:27+00:00

Example in VB I have a worker class Public Class worker Public Event EventNumber1(ByVal

  • 0

Example in VB I have a worker class

Public Class worker
    Public Event EventNumber1(ByVal messages As Dictionary(Of Integer, String))
    Public Event EventNumber2(ByVal message As String)

    Public Sub CallEventNumber1()
        Dim dict As New Dictionary(Of Integer, String)
        dict.Add(1, "EventNumber1 First message")
        dict.Add(2, "EventNumber1 Second message")
        RaiseEvent EventNumber1(dict)
    End Sub

    Public Sub CallEventNumber2()
        RaiseEvent EventNumber2("I am an EventNumber2 Message")
    End Sub
End Class

and wire them up in another class with

AddHandler _worker.EventNumber1, AddressOf EventNumber1Handler
AddHandler _worker.EventNumber2, AddressOf EventNumber2Handler

and in C# the worker class

class Worker
    {
        public delegate void EventNumber1Handler(Dictionary<int, string> messages);
        public delegate void EventNumber2Handler(string message);
        public event EventNumber1Handler EventNumber1;
        public event EventNumber2Handler EventNumber2;

        public void CallEventNumber1()
        { 
            Dictionary<int, string> dict = new Dictionary<int, string>();
            dict.Add(1, "EventNumber1 First message");
            dict.Add(2, "EventNumber1 Second message");
            if (EventNumber1 != null)
                EventNumber1(dict);
        }

        public void CallEventNumber2()
        { 
            if (EventNumber2 != null)
                EventNumber2("I am an EventNumber2 Message");
        }
    }

and wire that up with

worker.EventNumber1 += new Worker.EventNumber1Handler(worker_EventNumber1);
worker.EventNumber2 += new Worker.EventNumber2Handler(worker_EventNumber2);

So I guess my question is do I always need to add the delegate along with the event in c#? Is there any new syntax for c# 3.0/4.0?

Regards

_Eric

  • 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-14T19:09:28+00:00Added an answer on May 14, 2026 at 7:09 pm

    And then there is the strong recommendation that an event should always have the signature:

    delegate void MyEvent(objectr sender, MyEventArgs e);
    

    So you would also have to write a class deriving from EventArgs to encapsulate your Dictionary.

    The good news is that you can usually get away with the EventHandler<> and Action<> classes.

    public event Action<Dictionary<int,string>> EventNumber1;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

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.