DEV Community

Cover image for Nullable value Types | C#
Ozodbek
Ozodbek

Posted on

1

Nullable value Types | C#

Bugun biza o'rganishimiz shart bo'lgan narsalar quyidagicha πŸ‘‡

  • Declaretion va Assigment
  • Null bo'ladigan misollar qiymatlarini tekshirish
  • _Null qiymatni primative typega o'tqazish _
  • Vahokazolar

Null bu Value type! Odatda null qiymat biriktirish uchun asosan 1 ta belgidan foydalaniladi. Bu ? belgisi. Biz ko'pincha ishlatadigan Ma'lumot turlari o'z o'zidan null qiymat olishi mumkin emas. Misol uchun: bool? >> True, False, Null. Har qanday Null qiymat System.Nullable<T> Structurasiga tegishlidir.
Quyidagi almashtirilgan shakllardan birida T asosiy turga ega null qiymat turiga murojaat qilishingiz mumkin. Asosiy malumot turining aniqlanmagan qiymatini ko'rsatish uchun null dan foydalanish kerak.

Declaretion & Assigment

Declaretion - bu C# dasturlash tilida o'zgaruvchi e'lon qilib, unga qiymat berish. Assigment esa xuddi shu qiymat berish jarayonidagi = belgisi!
Practice

double? pi = 3.14;
char? letter = 'A';

int? son = 10; 
int? son2 = son;

bool? test = null;

// Ushbu ko'rsatilgan array Value type va Uning qiymati Null

int?[] sonlar = new int?[10];
Enter fullscreen mode Exit fullscreen mode

Null bo'lishi mumkin bo'lgan misol tekshiramiz!

int? a = 43; 
if (a is int valueOfA)
{
    Console.WriteLine($"a is {valueOfA}");
}
else
{
    Console.WriteLine("a does not have a value");
}
// Output:
// a is 42
Enter fullscreen mode Exit fullscreen mode

Davomi bor...

Image of Datadog

Master Mobile Monitoring for iOS Apps

Monitor your app’s health with real-time insights into crash-free rates, start times, and more. Optimize performance and prevent user churn by addressing critical issues like app hangs, and ANRs. Learn how to keep your iOS app running smoothly across all devices by downloading this eBook.

Get The eBook

Top comments (0)

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Retry later