Method Basics in C#

From the C# Programming Language cheat sheet · Methods (Functions) · verified Jul 2026

Method Basics

Creating and using methods

csharp
// Simple method
void SayHello()
{
    Console.WriteLine("Hello!");
}

// Method with parameters
void Greet(string name)
{
    Console.WriteLine($"Hello, {name}!");
}

// Method with return value
int Add(int a, int b)
{
    return a + b;
}

// Calling methods
SayHello();
Greet("Alice");
int sum = Add(5, 3);
💡 void means method doesn't return a value
⚡ Static methods belong to class, instance methods to objects
📌 Method overloading allows same name with different parameters
🟢 Use => for single-expression methods

More C# tasks

Back to the full C# Programming Language cheat sheet