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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T00:29:08+00:00 2026-06-01T00:29:08+00:00

I have a struct-array that contains details of different reports that can be run.

  • 0

I have a struct-array that contains details of different reports that can be run. Each report calls a different method and currently the program has to manually check the selected report value to specifically call the appropriate method.

I would like to store the method name in the struct-array and then have program invoke that method when there is match. Is this possible?

Currently:

if (this.cboSelectReport.Text == "Daily_Unload")
{
   reportDailyUnload();
 }

Ideally:

if(this.cboSelectReport.Text == MyArray[i].Name)
{
   something(MyArray[i].MethodName);
}

UPDATE

I tired a number of the suggestions below and none of them worked. They didn’t work probably due to how I have my program structured.

  • 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-01T00:29:09+00:00Added an answer on June 1, 2026 at 12:29 am

    You can do it using reflection, but IMO it is too fragile: it introduces an invisible dependency on the name of the method that you call.

    // Assuming that the method is static, you can access it like this:
    var namedReportMethod = "MyReport1";
    var reportMethod = typeof(ReporterClass).GetMethod(namedReportMethod);
    var res = reportMethod.Invoke(null, new object[] {reportArg1, reportArg2});
    

    A better approach would be to define a delegate based on your method, and store it in the struct/class instead of the method name.

    delegate void ReportDelegate(int param1, string param2);
    
    class Runner {
        public static void RunReport(ReportDelegate rd) {
            rd(1, "hello");
        }
    }
    
    class Test {
        static void TestReport(int a, string b) {
            // ....
        }
        public static void Main(string[] args) {
            Runner.RunReport(TestReport);
        }
    }
    

    Instead of defining your own delegate types, you can use pre-defined ones based on Action<T1,T2,...> or Func<T1,T2,R>, depending on your need to return values from the reports.

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

Sidebar

Related Questions

I have a structure in my program that contains a particular array. I want
Newbie here, I have a struct for a word, which contains a char array
I have a struct that's inside an array that is nested inside another struct,
I have a character array that contains serialized data that I need to interpret
I have an array of structures that contain multiple variables: struct test_case { const
I have an array of objects that have QTTime structs as attributes. The objects
I have a struct with a dynamic array inside of it: struct mystruct {
I have an array of structs and one of the fields in the struct
I have inherited a Visual Studio project that contains hundreds of files. I would
how can I manage to define a Set in OCaml that can contains element

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.