DEV Community

umida5
umida5

Posted on

Nulable Types

C# da nullable type (nolga qabul qiluvchi tur) qiymat turlariga null qiymatini berish imkonini beradi.

Nullable Type yaratish:

Nullable turlarni yaratish uchun qiymat turining orqasiga ? qo'shiladi. Misol:


int? nullableInt = null; // nullable int, hozirgi qiymati null

int? num = null;

if (num.HasValue) 
{
    Console.WriteLine(num.Value); // qiymat mavjud bo'lsa, chiqazadi
} 
else 
{
    Console.WriteLine("Null value"); // aks holda 0 chiqaradi
}

Enter fullscreen mode Exit fullscreen mode

Nullable turlar qiymat turlarini null qiymatini qabul qilish imkonini beradi va bu dasturlashda ko'plab holatlarni yanada qulayroq hal qilishga yordam beradi.

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more