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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T04:48:56+00:00 2026-05-20T04:48:56+00:00

I want to convert this C++ code to C#: typedef struct consoleCommand_s { char*

  • 0

I want to convert this C++ code to C#:

typedef struct consoleCommand_s 
{
    char* cmd          ;
    void (*function)() ;
} consoleCommand_t     ;



static consoleCommand_t commands[] = 
{
    {"clientlist", &CG__Clientlist},
    {"say", &CG_Say},
    {"nick", &CG_Nick},
    {"logout", &CG_Logout}
} ;

// e.g.
static void CG_Logout(void)
{
    // Logout
}

The closest i have come is this:

 public class Class1
    {
        // public delegate int Calculate (int value1, int value2);
        public delegate void fnCommand_t();

        public class consoleCommand_t
        {
            public string strCommandName; 
            public fnCommand_t fnCommand;

            public consoleCommand_t(string x, fnCommand_t y)
            {
                this.strCommandName = x;
                this.fnCommand = y;
            } // End Constructor

        } // End Class consoleCommand_t


        public static void Nick()
        {
            Console.WriteLine("Changing Nick");
        } // End Sub


        public static void Logout()
        {
            Console.WriteLine("Logging out");
        } // End Sub

        // string[] names = new string[] {"Matt", "Joanne", "Robert"};
        public consoleCommand_t[] commands = new consoleCommand_t[] {
            new consoleCommand_t("Nick",   Nick),
            new consoleCommand_t("Logout", Logout)
        };





    } // End Class Class1

Now I wanted to ask:

A) Why does Nick & Logout need to be static when all the rest is not ?
B) Is there no C-like way to initialize the commands array, that is, without new ?

  • 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-20T04:48:57+00:00Added an answer on May 20, 2026 at 4:48 am

    You could do without having a class INSIDE another class and manage your default console commands in another.

    public delegate void ConsoleCmd();
    
    public class DefaultCommands
    {
        public static void Nick()
        {
            Console.WriteLine("I'm Nick!");
        }
    
        public static void LogOut()
        {
            Console.WriteLine("You're Fired!");
        }
    }
    
    public class Console
    {
        private Dictionary<string, ConsoleCmd> mCommands;
    
        public Console()
        {
            mCommands = new Dictionary<string, ConsoleCmd>();
            mCommands.Add("Nick", DefaultCommands.Nick);
            mCommands.Add("Logout", DefaultCommands.LogOut);
        }
    }
    

    Accessing your commands would be as easy as:

    ConsoleCmd command = mCommands["Nick"];
    command();
    

    EDIT: Failed to mention this. This is to point to the OP that there are other better methods to achieve what he wants to do. And probably doesn’t answer his question but I hope will point him to the right direction in terms of his switch from functional programming language to purely object-oriented language.

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

Sidebar

Related Questions

I want to convert this C++ code to Python v2: static unsigned char asConvCode[3]
I want to convert function object to function. I wrote this code, but it
I want to convert this code into PHP, it's a function that hides layers
I have the following code in Ruby. I want to convert this code into
I want to convert this LINQ code var x = from nm in names
I have this code in Java and I want to convert it to C#.
I want to convert an iplimage to a cv::mat (not CvMat). With this code
I want to convert this url: module-apple-get.html?term=st to file.php?module=apple&func=get&term=st I 've wrote this code
Hi everyone i want to convert this xaml code to c# code please help
I have this php code saved in text file, I want to convert this

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.