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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T10:14:09+00:00 2026-06-18T10:14:09+00:00

I have a big static array of delegates that is the same for all

  • 0

I have a big static array of delegates that is the same for all instances of the class. I want to put references to instance methods in the array, i.e. open instance delegates. The compiler gives me an error. How do I do that?


Example code:

public class Interpreter
{
    // >7 instance fields that almost all methods need.

    private static readonly Handler[] Handlers = new Handler[]
    {
        HandleNop,          // Error: No overload for `HandleNop` matches delegate 'Handler'
        HandleBreak,
        HandleLdArg0,
        // ... 252 more
    };

    private delegate void Handler(Interpreter @this, object instruction);

    protected virtual void HandleNop(object instruction)
    {
        // Handle the instruction and produce a result.
        // Uses the 7 instance fields.
    }

    protected virtual void HandleBreak(object instruction) {}
    protected virtual void HandleLdArg0(object instruction) {}
    // ... 252 more
}

Some ideas that I’ve considered: providing all instance fields as parameters, but this becomes unwieldy very quickly. Initializing the list of handlers for each instance, but this would hurt performance very much (I need many instances of this class).

  • 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-18T10:14:10+00:00Added an answer on June 18, 2026 at 10:14 am

    Based on Jon Skeet’s answer on another question, the following will work:

    public class Interpreter
    {
        private static readonly Handler[] Handlers = new Handler[]
        {
            (@this, i) => @this.HandleNop(i),
            (@this, i) => @this.HandleBreak(i),
            (@this, i) => @this.HandleLdArg0(i),
            // ... 252 more
        };
    
        private delegate void Handler(Interpreter @this, object instruction);
    
        protected virtual void HandleNop(object instruction) {}
        protected virtual void HandleBreak(object instruction) {}
        protected virtual void HandleLdArg0(object instruction) {}
    }
    

    Direct support in C# would be much nicer. Maybe there is another way to do this that does not involve the indirection and extra typing?

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

Sidebar

Related Questions

I have a class that is mostly a wrapper for a big array and
I have big system that make my system crash hard. When I boot up,
I have big element at the top of the webpage that sides down with
I have big set of urls and I want to implement an autocompletion. I
I created a class Foo that has the method toArray() that returns an Array<Int>
Let's suppose that database is big. I have a very complex query for search
I have some markup that needs to be looped accordingly depending on the array,
I have a UICollectionViewFlowLayout that basically does what I want, except for one thing
i have a very big array which is shared among many functions in many
i have a big problem to bind this method: [Bindable(event=LOCALE_CHANGED_EVENT_TYPE)] public static function localeString(pathInLocale:String):String

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.