I'm creating an input text box on Forms, and I want specific commands to called certain procedures, e.g. "time" once entered would return with a MessageBox displaying the current time.
I currently use cases but wish to call the functions directly from a dictionary
private void enter_button_Click(object sender, EventArgs e)
{
Dictionary<string, Int64> commandDict = new Dictionary<string, Int64>()
{
["Do1"] = 1,
["Do2"] = 2,
["Do3"] = 3
};
long caseInput = 0;
try
{
caseInput = Convert.ToInt64(commandDict[(textBox1.Text).ToLower()]);
//Returns dict value as long integer /\
}
catch { }
switch (caseInput)
{
case 1:
Console.WriteLine("Do Thing 1")
break;
case 2:
Console.WriteLine("Do Thing 2")
break;
case 3:
Console.WriteLine("Do Thing 3")
break;
default:
Console.WriteLine("Incorrect Input")
break;
I want case 1,2 and 3 to be separate functions (their functionality has been downplayed but none return a value and none have input parameters). I would like commandDict (my current dictionary, to call these 3 procedures when the text "Do1" etc is inputted into "textBox1.Text".