In python, I can do something like this:
List=[3, 4]
def Add(x, y):
return x + y
Add(*List) #7
Is there any way to do this or something similar in C#? Basically I want to be able to pass a List of arguments to an arbitrary function, and have them applied as the function's parameters without manually unpacking the List and calling the function explicitly specifying the parameters.
Well, the closest would be reflection, but that is on the slow side... but look at MethodInfo.Invoke...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With