C# Methods

A method has a return type, a name, parameters, and a body. static means it belongs to the class itself, which is what lets Main call it without creating an object.

C#
using System;

class Program {
  static int Square(int n) {
    return n * n;
  }

  static void Main() {
    Console.WriteLine(Square(4));
    Console.WriteLine(Square(Square(2)));
  }
}
Read the full lesson