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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T14:12:38+00:00 2026-06-07T14:12:38+00:00

I have a program that will need to run different methods depending on what

  • 0

I have a program that will need to run different methods depending on what I want it to talk to, and I want to know if there is a way to store some sort of method pointer or something of that sort in an array. So I want an array where each element would be something like this:

[Boolean: Do_this?] [Function_pointer] [Data to pass to the function]

So basically, I can put this into a for loop and not call each function individually. Another block of code would fill in the Boolean of whether to run this function or not, and then my for loop would go through and run the function with its appropriate data if the Boolean is true.

I know delegates are similar to function pointers, but if that is the answer here, I’m not entirely sure how I would construct what I want to construct.

Is this possible in C#?

  • 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-07T14:12:39+00:00Added an answer on June 7, 2026 at 2:12 pm

    You could declare a specific object type to hold in a delegate, a flag that indicates whether to do that or now and the data. Note that what you are describing is very similar to events as they are also defined by a callback and some event data.

    The skeletal model would look something like this, assuming all methods you want to call have the same signature (you can work around that, if you need a whole bunch of various signatures by using reflection):

    // This reflects the signature of the methods you want to call
    delegate void theFunction(ActionData data);
    
    class ActionData
    {
        // put whatever data you would want to pass
        // to the functions in this wrapper
    }
    
    class Action
    {
        public Action(theFunction action, ActionData data, bool doIt)
        {
            this.action = action;
            this.data = data;
            this.doIt = doIt;
        }
    
        public bool doIt
        {
            get;
            set;
        }
    
        public ActionData data
        {
            get;
            set;
        }
    
        public theFunction action
        {
            get;
            set;
        }
    
        public void run()
        {
            if (doIt)
                action(data);
        }
    }
    

    And a regular use case would look something like this:

    class Program
    {
        static void someMethod(ActionData data)
        {
            Console.WriteLine("SUP");
        }
    
        static void Main(string[] args)
        {
            Action[] actions = new Action[] {
                new Action(Program.someMethod, new ActionData(), true)
            };
    
            foreach(Action a in actions) 
                a.run();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a java program, which will run on windows, which I want to
I have a console program that has different components that run like this: void
I have a program that I need to run under *nix and windows. because
I have a program that will let me manage users on our terminal server
I have the below program that will move files from one directory to other.
I have a java program that will work with a variety of Java Beans.
I have developed a Java program that will count the number of files in
For a school assignment I have to create a C++ program that will create
In my program, I've got a bunch of classes that will only ever have
I have program that runs fast enough. I want to see the number of

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.