Beginner C# - Learn C# - Methods Cheatsheet - Codecademy
Beginner C# - Learn C# - Methods Cheatsheet - Codecademy
● parameter names
● return type
● optional modifiers
Expression-Bodied Methods
In C#, expression-bodied methods are short methods
written using a special concise syntax. A method can only static int Add(int x, int y)
be written in expression body form when the method {
body consists of a single statement or expression. If the return x + y;
body is a single expression, then that expression is used }
as the method’s return value.
The general syntax is returnType funcName(args...) =>
static void PrintUpper(string str)
expression; . Notice how “fat arrow” notation, => , is
{
used instead of curly braces. Also note that the return
keyword is not needed, since the expression is implicitly Console.WriteLine(str.ToUpper());
returned. }
// Typical syntax
// (input-parameters) => { <statements> }