DEV Community

Sunnat Qayumov
Sunnat Qayumov

Posted on

16. Class va Object

a) C# dasturlash tilida objectni qanday yaratasiz?

class ClassName //sinf yaratish
{
    // Fields (ma'lumotlar)
    // Methods (xatti-harakatlar)
}
Enter fullscreen mode Exit fullscreen mode

b) Quyidagi kodda qanday xato bor?

class Person
{
    public string Name;

    public int Age;
}
Person p;
p.Name = "John";
Enter fullscreen mode Exit fullscreen mode

Xato: Person p deb yaratib bo'lmaydi. To'g'ri kod: Person p = new Person();

Top comments (0)