← C# tutorial

C#

Methods

A method declares its return type, name, and parameters up front: static int Square(int n) { ... }.

Example: a static method

using System;

class Program {
    static string Greet(string name) {
        return $"Hello, {name}!";
    }

    static void Main() {
        Console.WriteLine(Greet("Chidi"));
    }
}
Hello, Chidi!

Notice C# method names conventionally start with a capital letter (Greet, Main) — this is a real, widely-followed naming convention in C# (called PascalCase), distinct from Java's convention of starting method names lowercase (greet). Same underlying concept, different community convention — worth knowing so your code reads as idiomatic C#, not just "Java syntax translated."

Example
using System;

class Program {
    static string Greet(string name) {
        return $"Hello, {name}!";
    }

    static void Main() {
        Console.WriteLine(Greet("Chidi"));
    }
}
Output
Hello, Chidi!