wanto use a function as a parameter

in C# can this be done

private bool CallItUp(objetc o)
return (o's condition) true:false;
}

private void ProcessBy(object o)
{
PleaseHelpMe();
}

public static void main()
{
ProcessBy(CallItUp);
}

This is incorrect but i would like to now something simlar, possible



Answer this question

wanto use a function as a parameter

  • Dong Xie

    Yes its posible through delegates:

    Just have a quick look:

    private delegate bool FunctionRef(object o); // Should have same signature as function to which it holds reference

    private static FunctionRef functionRef = new FunctionRef (CallItUp) ;

    private static bool CallItUp(object o)

    return (o's condition) true:false;

    }


    public static void main()
    {
             functionRef (passedObject);
    }

    Delegate is basically a reference to the function or pointer to the function so you can pass it b/w functions and just call them like functions.

    A delegate's signature must match to the signature of function which this delegate is going to hold!

    I hope this is waht you need!

    Best Regards,



  • wanto use a function as a parameter