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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T02:49:48+00:00 2026-05-18T02:49:48+00:00

Please tell me what’s the different between Class1 and Class2 or the different between

  • 0

Please tell me what’s the different between Class1 and Class2 or the different between Event and Delegate ?
I test my class in Form1 and have the same result

//Class1.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class Class1EventArgs
{
    public StringBuilder CallStack;

    public Class1EventArgs() {
        CallStack = new StringBuilder();
    }
}

delegate void Class1EventHandler(Object sender, Class1EventArgs e);

class Class1
{
    public event Class1EventHandler EventDelegate;

    public void EventCaller()
    {
        Class1EventArgs e = new Class1EventArgs();
        e.CallStack.AppendLine("EventCaller");
        OnClass1Event(e);
    }

    protected virtual void OnClass1Event(Class1EventArgs e)
    {
        if (EventDelegate != null)            
        {               
            EventDelegate(this, e);
            System.Windows.Forms.MessageBox.Show(e.CallStack.ToString());
        }
    }

}

//Class2.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class Class2EventArgs
{
    public StringBuilder CallStack = new StringBuilder();
}

public delegate void Class2EventHandler(object sender,Class2EventArgs e);

class Class2
{
    public Class2EventHandler EventDelegate;

    public Class2()
    {
        EventDelegate = new Class2EventHandler(this.OnEventHappen);
    }

    public void EventCaller()
    {
        Class2EventArgs e = new Class2EventArgs();

        e.CallStack.AppendLine("EventCaller");

        EventDelegate.Invoke(this, e);

        System.Windows.Forms.MessageBox.Show(e.CallStack.ToString());
    }

    protected virtual void OnEventHappen(object sender, Class2EventArgs e)
    {
        e.CallStack.AppendLine("OnEventHappen");
    }

}

//Form1.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

public partial class Form1 : Form
{
    Class1 c1 = new Class1();
    Class2 c2 = new Class2();

    public Form1()
    {
        InitializeComponent();
    }

    #region "Button1"      

    private void button1_Click(object sender, EventArgs e)
    {
        c1.EventCaller();
    }

    private void c1_EvenDelegate(object sender, Class1EventArgs e)
    {
        e.CallStack.AppendLine("c1_EvenDelegate");
    }

    private void c1_EvenDelegate_2(object sender, Class1EventArgs e)
    {
        e.CallStack.AppendLine("c1_EvenDelegate_2");
    }

    #endregion

    private void Form1_Load(object sender, EventArgs e)
    {
        //c1 = new Class1();
        c1.EventDelegate += new Class1EventHandler(c1_EvenDelegate);
        c1.EventDelegate += new Class1EventHandler(c1_EvenDelegate_2);

        c2.EventDelegate += new Class2EventHandler(c2_OnEventHappen1);
        c2.EventDelegate += new Class2EventHandler(c2_OnEventHappen2);
    }

    private void button2_Click(object sender, EventArgs e)
    {
        c2.EventCaller();
    }

    private void c2_OnEventHappen1(object sender, Class2EventArgs e)
    {
        e.CallStack.AppendLine("c2_OnEventHappen1");
    }

    private void c2_OnEventHappen2(object sender, Class2EventArgs e)
    {
        e.CallStack.AppendLine("c2_OnEventHappen2");
    }
}
  • 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-18T02:49:49+00:00Added an answer on May 18, 2026 at 2:49 am

    Event is a special system stack-like variable which holds pointer(s) to functions. An event can hold a only special type of functions as its defined by a delegate.
    Delegate is type for a function – it’s like a definition of what a function signature must look like: this function must have 2 int parameters. This is what basically a delegate means to the system. When you instantiate a delegate with a function which matches its description the instance of the delegate now holds address of that function. Is this clear somewhat or not yet … ?:) This is how I see it.

    So basically an event holds a pointer to pre-defined void type of function(the delegate type).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please tell me whats wrong with this c# code.. public bool CloseCOMPort() { try
hi Please tell me how to apply multiple valued sort order in solr here
So can someone please tell why neither of these options will actually submit the
Could someone please tell me if there is someway to invoke the SQL Script
Can someone please tell me what I am doing wrong here? <script type=text/javascript> (document).ready(function()
Could you please tell me how can I get from CompilerError instance exact text
Can anyone please tell me method for checking oracle data base network status?
Can anyone please tell me what is the prefered way to manage transaction when
Can anybody please tell me what about visible and includeInLayout properties of a component
Can anybody please tell me why should I use the NonAction attribute? I mean

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.