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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T14:20:27+00:00 2026-06-05T14:20:27+00:00

If I only register one method of one class to a delegate, I can

  • 0

If I only register one method of one class to a delegate, I can use the delegate.Target, but when I subscripe more methods from different classes this does not work anymore. Is there another way to access the subscribers list of this delegate?

Here is the code: The foreach loop is being evaluated to null at runtime (it compiles)

    public delegate void WriteMessage(string msg);

internal class Program
{
    private static void Main(string[] args)
    {
        var myClass = new MyClass();
        var writer = new WriteMessage(myClass.WriteMessage);

        writer += SaySomething; //method in this class
        writer += myClass.SayShit; //instance class
        writer += AnotherClass.Say; //static class

        foreach(string target in (string[])writer.Target)
        {
            Console.WriteLine(target);
        }

        Console.ReadLine();
    }

    private static void SaySomething(string msg)
    {
        Console.WriteLine("HI!!!!");
    }
}

complete code:
http://pastebin.com/AzzRGMY9

  • 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-05T14:20:29+00:00Added an answer on June 5, 2026 at 2:20 pm
    Delegate[] list = delegate.GetInvocationList();
    

    That will get you an array of Delegate objects, which you can use to get the list of Targets.

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

Sidebar

Related Questions

I am java and php programmer. In java i can use static class/method so
Only one instance of a Script Manager can be added to the page. Such
I have a Class called User, and have 2 methods, one is login, another
I have a register page that saves the data to a database the only
I only have one computer (running OS X), and need to test in both
I'm wondering how one can do that. Afaik there is BeanFactoryPostProcessor interface that let
There are plenty of ways to bind a SOURCE method to target property, either
I am trying to use Generic DataContract class so that I don't have to
I currently use CodeIgniter as my framework of choice when using PHP. One of
I've built an appWidget which register some services on his onEnabled() method. The problem

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.