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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:36:26+00:00 2026-05-27T22:36:26+00:00

My colleague and I came across this when looking into getting the invocation list

  • 0

My colleague and I came across this when looking into getting the invocation list of a delegate. If you create an event in say class X, then you can access the public methods of the event fine from within that class. But (and please ignore stuff like why you’d have public access to class members, this isn’t what we’re asking!), if we have a class Y instantiating X, and accessing the event within X, it can’t call any of the public methods such as GetInvocationList() of the event. We wanted to know how this works. Here is a code sample (read the comments to see what we mean):

    public class X
    {
        public delegate void TestMethod();

        public event TestMethod testMethod;

        private void rubbish()
        {
            // can access testMethod.GetInvocationList() fine here
            testMethod.GetInvocationList(); 
        }
    }

    public class Y
    {
        public Y()
        {
            X x = new X();
            x.testMethod += this.test;

            // here it says testMethod can only appear on the left hand side of += or -=
            // why is this? (i.e. the below line is invalid)
            x.testMethod.GetInvocationList(); 
        }

        public void test()
        {
        }
    }

Out of curiosity how do you achieve this, and what’s the reason for having this feature avaialble?

Many Thanks
Amit

  • 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-27T22:36:27+00:00Added an answer on May 27, 2026 at 10:36 pm

    That’s what the event keyword does; it is a modifier that restricts operations other than subscription to the owning class. If you remove the event keyword you will end up with a plain delegate that clients outside the class can call e.g. the GetInvocationList() method on.

    In a blog post they compare the generated IL code for a plain delegate and an event and it is handled exactly the same. The event keyword is a compile-time modifier that restricts access to the methods of the delegate. (It also enables use in interfaces). All the details are in the blog post.

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

Sidebar

Related Questions

Yesterday I read some code of a colleague and came across this: class a_class
I came across this problem via a colleague today. He had a design for
A colleague came across some code that looked like this and couldn't understand how
I just came across a piece of code written by my ex-colleague few years
I was looking through some code from the SDL library and came across a
Say I have some special class, WrappedDataTable , and I want to associate each
A colleague of mine is looking for a method in System.IO that will do
Today, while talking with my colleague, something odd came out of his mind. A
Possible Duplicate: Learning efficient algorithms I recently came across an problem that was solved
A colleague came to me with a problem that I managed to answer but

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.