DEV Community

Mushtariy
Mushtariy

Posted on

Class va Constructor

a) Constructor nima?

Construktor – sinfdan obyekt yaratilganda avtomatik chaqiriladigan maxsus usuldir. U obyekning dastlabki qiymatini 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);
Enter fullscreen mode Exit fullscreen mode

Top comments (0)