Question

I ran into this while using slimDX

MessagePump.Run(form, () => { });

What does () => { } do?

Was it helpful?

Solution

The expression () => {} is an empty lambda expression. The function MessagePump.Run is defined as:

public static void Run(
Form form,
MainLoop mainLoop
)

MainLoop is defined as:

public delegate void MainLoop()

So it is delegate which does not expects any parameters. So when you pass () => {} it is as good as a method that do nothing like:

public void MainLoopImpl()
{
    //empty method
}

Now create MainLoop instance:

var mLoop = new MainLoop(MainLoopImpl);
//or alternative syntax
MainLoop mLoop = MainLoopImpl;

//CALL Run

MessagePump.Run(form, mLoop);

Details about declaring, creating and using delegates (including lambda expression declaration way) is explained in detail on this MSDN page.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top