Expression-bodied methods - CSharp Custom Type

CSharp examples for Custom Type:Method

Introduction

A method that comprises a single expression, such as the following:

int Foo (int x) { return x * 2; }

can be written more tersely as an expression-bodied method.

A arrow replaces the braces and return keyword:

int Foo (int x) => x * 2;

Expression-bodied functions can also have a void return type:

void Foo (int x) => Console.WriteLine (x);

Related Tutorials