7. Class va Constructor
Zahro
Posted on October 11, 2024
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;
}
}
Animal dog = new Animal("Dog");
Console.WriteLine(dog.Name);
💖 💪 🙅 🚩
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.