Nullable value Types | C#

ozodbek_soft

Ozodbek

Posted on June 5, 2024

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...

💖 💪 🙅 🚩
ozodbek_soft
Ozodbek

Posted on June 5, 2024

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

Nullable value Types | C#
dotnet Nullable value Types | C#

June 5, 2024