You woke up in the morning, brushed your teeth. Did it again at noon. And in the evening. You repeated the same action every time — but you only learned it once.
Code works the same way. Instead of writing the same thing over and over, you write it once, give it a name, and call it whenever needed. This is called a method.
static void Selamla()
{
Console.WriteLine("Merhaba!");
}
Selamla();
Selamla();
Selamla();
Code written without methods quickly becomes unreadable. Imagine copying the same block to 10 places — if you find a bug in one, you have to fix all 10.
Methods make code readable, maintainable, and reusable. These three properties are the foundation of good software.
Some methods do something but don't return a value — these are void. Others produce something and give it back.
Think of a cook in the kitchen: a void cook makes the food but doesn't hand it to you. A return cook cooks it and hands you the plate.
static void Yazdir(string mesaj)
{
Console.WriteLine(mesaj);
}
static int Topla(int a, int b)
{
return a + b;
}
Yazdir("Merhaba");
int sonuc = Topla(3, 5);
Console.WriteLine(sonuc);
You can pass information into methods from outside — these are called parameters. Think of a calculator: it doesn't just add, you also need to tell it which numbers to add.
static void Karşıla(string isim)
{
Console.WriteLine($"Merhaba, {isim}!");
}
Karşıla("Emre");
Karşıla("Ayşe");
Karşıla("Mehmet");
There are some fundamental rules learned over years. Knowing these separates you from mid-level developers: