How do you store a function in a variable in c#?

I want to be able to store a function in a variable, so that later i can call it from that variable?


this question has already been answered (check the link below), let me know if the article helped you or if you need further help :slight_smile:

Use and Action if the function does not return a value and a Func if it does


private Func<int, int, out int> myFunction;

int Add(int a, int b){
    return a + b;

int Subtract(int a, int b){
    return a - b;

void DoStuff(){
    int a = 10;
    int b = 5;

    myFunction = Add;

    myFunction = Subtract;