How can I start the task by string?

Ffurras10/2/2022
I need something like this, is this possible to do?

void Main()
{
var input = Console.ReadLine();
Task.Run(() => input );
}
BBecquerel10/2/2022
what would this do?
Ffurras10/2/2022
start a task by it's name(string input from user)
BBecquerel10/2/2022
tasks don't have names
BBecquerel10/2/2022
if i typed in "hello", in that example, what would you expect to happen
Ffurras10/2/2022
If I type "ping" - start task ping
Image
BBecquerel10/2/2022
ok, that's a method called ping, not a task
BBecquerel10/2/2022
i would suggest something like this
BBecquerel10/2/2022
var dictionary = new Dictionary<string, Func<Task>>()
{
  { "ping", () => ping() },
  { "blah", () => otherMethod() },
};

var userInput = Console.ReadLine();

if (dictionary.TryGetValue(userInput, out var action))
{
  var task = action.Invoke();
  await task;
}
else
{
  Console.WriteLine("no method found");
}
Ffurras10/2/2022
okay, I will try it
Ffurras10/2/2022
thx :)
BBecquerel10/2/2022
:dogeburger3:
Ffurras10/2/2022
That's work. Thank you so much
BBecquerel10/2/2022
:swagyes: