Defining a method
A method is a named block of code that does one job. You write it once, then run it by its name as often as you need. Lines 5 to 8 define a method called Add.
Line 5 is the signature. int is the return type: Add hands back an int. Add is the name. In the brackets are two parameters, a and b: named inputs, each with a type. The body sits between { and }.
Calling it
Line 1 calls Add(2, 3). Line 1 waits while the program jumps into Add. A new frame, a small box of memory for this call, goes on top of the call stack. The arguments 2 and 3 are copied into a and b.
Now the body runs. Line 7, return a + b, adds the two parameters: 2 + 3 = 5. Parameters work like local variables: they exist only inside this one call.
return ends the call and sends 5 back to the caller. Add's frame is removed from the stack. Line 1 carries on where it left off and stores the value: x now holds 5.
Line 2 reuses the same method with new arguments: Add(x, 10). The value of x, 5, is copied into a, and 10 into b. A fresh frame goes on the stack; the first one is long gone.
This time return a + b gives 5 + 10 = 15. The frame is removed again and y holds 15. One method, written once, did two different sums.
Methods everywhere
Line 3 calls another method, Console.WriteLine, which comes with .NET. Its return type is void: it hands nothing back. It just prints 15 in the console, and then the program ends.
The compiler checks every call against the signature. Add("2", 3) passes a string where an int belongs: error CS1503. Add(2) leaves out b: error CS7036. Such mistakes stop the build before anything runs.
What happens
// step 1/9 · method
1 int x = Add(2, 3);
2 int y = Add(x, 10);
3 Console.WriteLine(y);
4
5 static int Add(int a, int b)
6 {
7 return a + b;
8 }
lines 1-3 top-level statements: they run first, top to bottom
lines 5-8 the method Add: it only runs when it is called
The call stack here is simplified: a real frame also holds the return address and other bookkeeping, and the JIT compiler may keep small values like a and b in CPU registers or inline a tiny method like Add. With top-level statements, a method written in Program.cs is strictly a local function; the compiler turns it into an ordinary method. static means it cannot use the top-level variables x and y, only its own parameters. In larger programs methods live inside a class.