Simple C# Noop Statement

Protector one picture Protector one · Aug 3, 2011 · Viewed 28.2k times · Source

What is a simple Noop statement in C#, that doesn't require implementing a method? (Inline/Lambda methods are OK, though.)

My current use case: I want to occupy the catch-block of a try-catch, so I can step into it while debugging and inspect the exception.
I'm aware I should probably be handling/logging the exception anyway, but that's not the point of this exercise.

Answer

AHM picture AHM · Aug 3, 2011

If you really want noop, then this defines a nameless action that doesn't do anything, and then invokes it, causing nothing to happen:

((Action)(() => { }))();