Syntax

C# Define a Method Syntax

In C#, define a method: defines a method — static int Add(int a, int b) => a + b;

Quick Answer

Syntax
static int Add(int a, int b) => a + b;
C#Syntax

Define a Method

Code example
static int Add(int a, int b) => a + b;

Defines a method.

Learn More

How to define a method in C#

  1. Open your C# file or editor.
  2. Copy the example, then replace its sample names and values for your code.

C# Define a Method Syntax

Use static int Add(int a, int b) => a + b;.

Related Syntax References

Frequently asked questions

What is the C# syntax for define a method?

Use this pattern: static int Add(int a, int b) => a + b;

Can I copy this C# code example?

Yes. Use Copy code and adapt the example to your program.

Is this C# syntax different on Mac or Windows?

No. The language syntax is the same across operating systems.

Official source · How we verify