I wanted to have a hashtable with a string as key and a functionpointer (delegate) as value. This way calling the correct routine given a string based command. However, the compiler won't eat it.
What am I doing wrong?
//declaration
public delegate void categoryHandler(String request);
//init code
Hashtable categories = new Hashtable();
categories.Add("campaigns", Campaigns.post);
//function call
String category = "campaigns";
categoryHandler handler = (categoryHandler) categories[category];
if (handler != null)
{
handler(someString);
}
//handler
static public void post(String request)
{
...
}
The error I get is on the line where I put the function in the hashtable: Error 2 Argument '2': cannot convert from 'method group' to 'object'
I'm hoping it is just some semantic thingy I forgot... But if this can't be done... is there another way to have some kind of String based jumptable?