0

In python, I can find the corresponding function with the function name like this:

### testa.py
def funca(a=0, b=1):
    print("aaa", a, b)

def funcb(a=2, b=3):
    print("bbb", a, b)

func_dict = {"a": funca, "b": funcb}

def main():
    inp = input()
    if func_dict.get(inp):
        func_dict[inp](1, 2)

if __name__ == "__main__":
    main()

How can I implement the similar function in C#?

malofleur
  • 43
  • 4
  • 2
    In exactly the same way. .NET provides dictionaries and delegates. I'd expect `Dictionary>` for the example you've provided, though you can also use `Func` for methods that return something, or even create your own delegate. – ProgrammingLlama Jun 28 '22 at 01:22
  • [Dictionary docs](https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.dictionary-2?view=net-6.0), [Delegates docs](https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/delegates/), [Action delegate docs](https://learn.microsoft.com/en-us/dotnet/api/system.action?view=net-6.0), [Func delegate docs](https://learn.microsoft.com/en-us/dotnet/api/system.func-1?view=net-6.0) – ProgrammingLlama Jun 28 '22 at 01:24

0 Answers0