Methods
A method lives inside a class and has a return type, a name, and a list of parameters. static methods, like the ones in this lesson, belong to the class itself rather than to any particular instance, which is why Main() — itself static — can call them directly.
Main.cs
Try it yourself →using System;
class Program {
static int Multiply(int a, int b) {
return a * b;
}
static void Main() {
Console.WriteLine(Multiply(6, 7));
}
}Output
42
C# also supports method overloading — declaring multiple methods with the same name as long as their parameter types differ, with the compiler picking the right one at compile time based on the call site's argument types.
Next: arrays and lists — C#'s fixed-size arrays versus the growable List<T>.
Practice exercise
Write a method Multiply(int a, int b) that returns a * b, then print Multiply(6, 7).