Home About Lessons Blog On The Mic Contact Projects
Lessons BASIC · C#

C# Basics — Class and Object

9 min read · Emre Ulutabak
1
What is a class?

Imagine you want to build a car. First you need a design: how many doors, what color, what engine type. That design itself is not yet a real car.

In software, the similar concept is a class. A class is the blueprint or template of an object.

csharp
class Araba
{
    public string Marka;
    public int Yil;
}
💡
A class does not represent the real object itself, but describes how it should look.
2
What is an object?

When you create a real example from the blueprint, you now have an actual object. That is called an object.

So if the class is the plan, the object is the realized version of that plan.

csharp
Araba araba1 = new Araba();
araba1.Marka = "Toyota";
araba1.Yil = 2022;
💡
With the new keyword, you create a real object from a class.
3
Instantiation logic

You can create multiple objects from the same class. Think of many phones of the same model, each with different colors and owners.

They all come from the same blueprint, but each object can hold different values.

csharp
Araba araba1 = new Araba();
araba1.Marka = "BMW";

Araba araba2 = new Araba();
araba2.Marka = "Mercedes";
💡
The same class can create many objects carrying different data.
4
Property and method

A class can contain data, which you can think of as properties or fields. It can also contain behaviors, which are called methods.

So an object can both store information and perform actions.

csharp
class Araba
{
    public string Marka;

    public void Calistir()
    {
        Console.WriteLine("Araba çalıştı.");
    }
}
💡
A property represents the object's data, while a method represents its behavior.
5
Golden rules

Classes and objects are the foundation of object-oriented programming. They may feel abstract at first, but examples make them click quickly.

💡
Think of the class as the mold, and the object as the real product made from that mold.
💡
If a class is doing too many things, consider simplifying it.
💡
Naming matters a lot. Class names are usually nouns: Car, Customer, Order, and so on.
MINI QUIZ
Which of the following is correct?
An object is the blueprint of a class
A class is the template used to create objects
The new keyword deletes a class
Only one object can be created from a class