DEV Community

Ozodbek
Ozodbek

Posted on

Properties in C# | Uzbek

Salom barchaga. Bugun biza C# dasturlash tilida o'rganishimiz kerak bo'lgan ba'zi bir tushunchalar haqida aytib beraman.
`** Reja: **

  • Property nima ?
  • Property turlari
  • Propertydan foydalanish
  • Amaliyot va tushunchalar
  • Quizlar`

*Property nima ? *
Property(xususiyat) C# dasturlash tilida obyektlar, classlar va strukturalar ichida ma'lumotni saqlash va olish uchun ishlatiladigan maxsus a'zolar(member)dir. Propertylar fieldlar(maydonlar) kabi ko'rinadi. Va ular getter va setter orqali maydonga kirish imkonyatini beradi.

Property turlari: **
1 - **Auto implemented property
- Bu turdagi propertylar soddalashtirilgan holda yoziladi, bu yerda get va set methodlari automatik ravishda yoziladi.
2 - Read-Only Property - Faqat o'qish uchun belgilangan propertylar. get funksiyasi ishlaydi xolos, set qo'sha olmaymiz.
3 - Write-Only Property - Faqat yozish mumkin bo'lgan propertylar, faqat set metodi bilan ta'minlanadi.
4 - Calculated Properties - Hisob kitobli propertylar, get va set methodlari maxsus hisob-kitoblarni amalga oshirish uchun ishlatiladi.

Amaliyotni boshladik πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€

Auto-Implemented Property

public class Person 
{
    public string Name { get; set; }
    public int Age { get; set; }
}
Enter fullscreen mode Exit fullscreen mode

*Read-Only Property *

public class Person2 
{
    private string name; 

    public Person2 (string name)
    {
        this.name = name;
    }
    public string Name 
    {
        get {return name;}
    }
}
Enter fullscreen mode Exit fullscreen mode

Write-Only Property

public class Person3 
{
    private string password; 

    public string Password 
    {
        set {password = value;}
    }
}
Enter fullscreen mode Exit fullscreen mode

davomi bor....

Top comments (0)