So i have 2 classes named A and B.
A has a method “public void Foo()”.
B has several other methods.
What i need is a variable in class B, that will be assigned the Foo() method of class A.
This variable should afterwards be “executed” (=> so it should execute the assigned method of class A).
How to do this?
Reed gave you the right answer. It’s also worth pointing out that you can use other delegate signatures besides Action.
There are generic versions like
Action<T>(one arg),Action<T1, T2>(two args), etc…Also if your method has a return type, check out
Func<T, TResult>.Or of course you can define your own delegate type.