GeekPeek
GeekPeek

Reputation: 1767

How can I define a delegate function in the function call?

I have a delegate function that does a callback. What I want to do is the following:

delegate void someDelegate( int i );
callFunction( int i, someDelate del )
{
    del.invoke( i );
}
callFunction( 10, void( int i )
{ 
    printf( i ); 
} );

I know this is possible but I cannot find it anymore.

Upvotes: 0

Views: 74

Answers (1)

Jenish Rabadiya
Jenish Rabadiya

Reputation: 6766

Is lambda syntax like this what are you looking for?

class Program
{
    static void Main(string[] args)
    {
        callFunction(10, (i) =>
        {
            //printf( i ); 
        });
    }

    public delegate void someDelegate(int i);
    public static void callFunction(int i, someDelegate del)
    {
        del.Invoke(i);
    }

}

Upvotes: 4

Related Questions