Expression-bodied method: Return nothing

Methods which do nothing still make sense - they just do nothing.

You can lose the return statement:

  private void SomeMethod() { }

Or assign a function to a variable instead:

  private Action SomeMethod = () => { };

If you really want to do expression for body on void function, you can do this:

private void SomeFunction() => Expression.Empty();

This uses Linq and creates an empty expression that has Void type.


That's not an expression body, but you can do this:

private void SomeMethod() { }

Tags:

C#

C# 6.0