7. Class va Constructor

zahro_11eecc01a1cfe5142b9

Zahro

Posted on October 11, 2024

7. Class va Constructor

a) Constructor nima?

Constructor — bu class ning maxsus metodi bo'lib, u yangi obyekt yaratilganda avtomatik ravishda chaqiriladi. Constructor odatda obyektning dastlabki qiymatlarini o'rnatish uchun ishlatiladi.

b) Quyidagi kodni to'ldiring:

class Animal 
{
    public string Name;

    public Animal(string name) 
    {
        Name = name;
    }
}
Enter fullscreen mode Exit fullscreen mode

Animal dog = new Animal("Dog");
Console.WriteLine(dog.Name);

💖 💪 🙅 🚩
zahro_11eecc01a1cfe5142b9
Zahro

Posted on October 11, 2024

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related