Methods
In C#, functions are called methods. A method has a return type, a name and parameters: static int Square(int n) { return n * n; }
static lets Main call the method without creating an object first; you'll see why in the classes lesson. void means a method returns nothing.
By convention, C# method names start with a capital letter: Square, PrintReceipt.
Example
static string Greet(string name)
{
return $"Hello, {name}!";
}
static void Main()
{
Console.WriteLine(Greet("Ada"));
}
Output
Hello, Ada!
Methods live inside the class, next to Main, not inside Main.
Your tasks
0 of 3 done- Define static int Area(int width, int height)
- Return width multiplied by height
- Call Area a second time with other numbers
Tutor
The tutor guides you toward the answer instead of handing it over. It uses your own Claude usage.
Quick check
Why is Area marked static here?
No problems found. Unclosed tags, missing semicolons and errors show up here in plain words.