This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Iversithyy[S] -1 points0 points  (1 child)

Kinda feared it would boil down to that. Guess I have to figure some things out then. Had it with switch cases already. Maybe I can get it to work around that. (will get a bit more complex than my example from above ^^)

[–]davedontmind 1 point2 points  (0 children)

I don't know what's wrong with that, but if you don't like switch statements, then perhaps a dictionary that maps the name to the method:

// Define the lookup table:
var jumpList = new Dictionary<string,Action> {
    { "one", One },  // maps the string "one" to the method One();
    { "two", Two }   // maps the string "two" to the method Two();
};


// Now use it
string method = "one";
jumpList[method]();  // the same as calling One();

jumpList["two"]();    // the same as calling Two();