Search code examples
c#no-op

Simple C# Noop Statement


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.


Solution

  • 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)(() => { }))();