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

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs