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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:30:35+00:00 2026-06-15T14:30:35+00:00

I have this simple event : public class ClassA { public event Func<string, int>

  • 0

I have this simple event :

public class ClassA
{
    public event Func<string, int> Ev;
    public int Do(string l)
    {
        return Ev(l);
    }
}

And 2 Methods :

  static int Display(string k)
        {
            return k.Length;
        }

  static int Display_2(string k)
        {
            return k.Length*10;
        }

Im registering this event :

 ClassA a = new ClassA();
 a.Ev += Display;
 a.Ev += Display_2;

Now , I’m executing :

   Console.WriteLine(a.Do("aaa")); 

the output :

enter image description here

What ???

  • he has in invocation list 2 methods ! it did run them , but why does it shows only the result from the last registration ?

  • Where does the result of "3" has gone ? ( the first invocation ) ? ( although both display+display_2 was executed… I didn’t expect console.write to iterate through results . but also didn’t expect him to decide which to show.)

edit :

enter image description here

  • 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-06-15T14:30:36+00:00Added an answer on June 15, 2026 at 2:30 pm

    There are three aspects at play here:

    1. The implementation of the event
    2. The behaviour of delegate combination
    3. The behaviour of invoking a delegate whose invocation list has multiple entries

    For point 1, you have a field-like event. Section 10.8.1 of the C# 4 spec gives an example, and states that:

    Outside the declaration of the Button class, the Click member can be used only on the left-hand saide of the += and -= operators, as in

    b.Click += new EventHandler(...);
    

    which appends a delegate to the invocation list of the Click event

    (emphasis mine). The spec also makes it clear that a field-like event creates a delegate field, which is used from within the class for invocation.

    More generally (point 2), section 7.8.4 of the C# 4 spec talks about delegate combination via + and +=:

    Delegate combination. Every delegate type implicitly provides the following predefined operator, where D is the delegate type:

    D operator +(D x, D y)
    

    The binary + operato performs delegate combination when both operands are of some delegate type D. [… skip bits where x or y are null …] Otherwise, the result of the operation is a new delegate that, when invoked, invokes the first operand and then invokes the second operand.

    (Again, emphasis mine.)

    Finally, point 3 – event invocation and return values. Section 15.4 of the C# spec states:

    If the delegate invocation includes output parameters or a return value, their final value will come from the invocation of the last delegate in the list.

    More generally, it depends on the event implementation. If you use an event implementation which uses the "normal" delegate combination/removal steps, everything is guaranteed. If you start writing a custom implementation which does crazy things, that’s a different matter.

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

Sidebar

Related Questions

I'm trying to implement simple Event Bus I started like this: public class RegistrationData
I created a very simple event publisher and it looks like this. public class
I have this simple piece of code : int a = 1, b =
I have this simple code of node addon: #include <node.h> #include <v8.h> #include <string>
I have a very simple class: People: class People { private string LastName =
I have code like this: class Base { public: void operator = (const Base&
I have a simple interface for caching stuff which goes like this public interface
I have a very simple class that I'm trying to serialize: [ProtoContract] public class
So i have this code: public class StreamingMp3Player extends Activity implements OnClickListener, OnTouchListener, OnCompletionListener,
I have a class namespace LogToolsTest { public class Foo { private static readonly

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.