DEV Community

Cover image for C# da Data tiplar haqida
islomAli99
islomAli99

Posted on

C# da Data tiplar haqida

Assalamu aleykum hurmatli dasturchilar, C# tilida ma'lumot turlari (data types) haqida tushuncha beraman. Quyidagi misollar yordamida har bir turdagi o'zgaruvchilarni qanday ishlatishni ko'rsataman.

  1. bool bool — bu ma'lumot turi true yoki false qiymatlarini saqlaydi.
bool isStudent = true;
bool isTeacher = false;

Console.WriteLine(isStudent);  // Natija: True
Console.WriteLine(isTeacher);  // Natija: False

Enter fullscreen mode Exit fullscreen mode
  1. byte byte — bu 1 baytli butun son bo'lib, qiymati 0 dan 255 gacha bo'lishi mumkin.
byte age = 25;  // 0 dan 255 gacha
Console.WriteLine(age);  // Natija: 25

Enter fullscreen mode Exit fullscreen mode
  1. sbyte sbyte — bu 1 baytli butun son bo'lib, qiymati -128 dan 127 gacha bo'lishi mumkin.
sbyte temperature = -5;  // -128 dan 127 gacha
Console.WriteLine(temperature);  // Natija: -5

Enter fullscreen mode Exit fullscreen mode
  1. short short — bu 2 baytli butun son bo'lib, qiymati -32,768 dan 32,767 gacha bo'lishi mumkin.
short year = 2024;
Console.WriteLine(year);  // Natija: 2024

Enter fullscreen mode Exit fullscreen mode
  1. ushort ushort — bu 2 baytli butun son bo'lib, qiymati 0 dan 65,535 gacha bo'lishi mumkin.
ushort maxScore = 65000;
Console.WriteLine(maxScore);  // Natija: 65000

Enter fullscreen mode Exit fullscreen mode

6.int
int — bu 4 baytli butun son bo'lib, qiymati -2,147,483,648 dan 2,147,483,647 gacha bo'lishi mumkin.

int population = 1000000;
Console.WriteLine(population);  // Natija: 1000000

Enter fullscreen mode Exit fullscreen mode
  1. uint uint — bu 4 baytli butun son bo'lib, qiymati 0 dan 4,294,967,295 gacha bo'lishi mumkin.
uint distance = 3000000000;
Console.WriteLine(distance);  // Natija: 3000000000

Enter fullscreen mode Exit fullscreen mode
  1. long long — bu 8 baytli butun son bo'lib, qiymati -9,223,372,036,854,775,808 dan 9,223,372,036,854,775,807 gacha bo'lishi mumkin.
long worldPopulation = 7800000000;
Console.WriteLine(worldPopulation);  // Natija: 7800000000

Enter fullscreen mode Exit fullscreen mode
  1. ulong ulong — bu 8 baytli butun son bo'lib, qiymati 0 dan 18,446,744,073,709,551,615 gacha bo'lishi mumkin.
ulong starsInGalaxy = 1000000000000000000;
Console.WriteLine(starsInGalaxy);  // Natija: 1000000000000000000

Enter fullscreen mode Exit fullscreen mode
  1. float float — bu 4 baytli suzuvchi nuqtali son bo'lib, qiymati -3.4 * 10^38 dan 3.4 * 10^38 gacha bo'lishi mumkin.
float temperature = 36.6f;
Console.WriteLine(temperature);  // Natija: 36.6

Enter fullscreen mode Exit fullscreen mode
  1. double double — bu 8 baytli suzuvchi nuqtali son bo'lib, qiymati ±5.0 * 10^-324 dan ±1.7 * 10^308 gacha bo'lishi mumkin.
double pi = 3.14159265358979;
Console.WriteLine(pi);  // Natija: 3.14159265358979

Enter fullscreen mode Exit fullscreen mode
  1. decimal decimal — bu 16 baytli o'nli nuqtali son bo'lib, qiymati ±1.0 * 10^-28 dan ±7.9228 * 10^28 gacha bo'lishi mumkin. U 28 ta raqamni aniqlik bilan saqlay oladi.
decimal price = 199.99m;
Console.WriteLine(price);  // Natija: 199.99

Enter fullscreen mode Exit fullscreen mode
  1. char char — bu 2 baytli bir belgini saqlaydi (Unicode kodlashda).
char letter = 'A';
Console.WriteLine(letter);  // Natija: A

Enter fullscreen mode Exit fullscreen mode
  1. string string — bu Unicode belgilardan iborat matnni saqlaydi.
string greeting = "Salom, dunyo!";
Console.WriteLine(greeting);  // Natija: Salom, dunyo!

Enter fullscreen mode Exit fullscreen mode
  1. object object — bu har qanday ma'lumot turini saqlay oladigan umumiy ma'lumot turidir.
object obj1 = 42;
object obj2 = "Hello";
object obj3 = 3.14;

Console.WriteLine(obj1);  // Natija: 42
Console.WriteLine(obj2);  // Natija: Hello
Console.WriteLine(obj3);  // Natija: 3.14

Enter fullscreen mode Exit fullscreen mode
  1. var var — bu ma'lumot turi emas, balki C# sintaksisida turlarni aniqlashni soddalashtiradigan kalit so'zdir. var bilan deklaratsiya qilingan o'zgaruvchining turi kompilyator tomonidan aniqlanadi.
var number = 10;         // int turida
var name = "John";       // string turida
var price = 19.99;       // double turida

Console.WriteLine(number);  // Natija: 10
Console.WriteLine(name);    // Natija: John
Console.WriteLine(price);   // Natija: 19.99

Enter fullscreen mode Exit fullscreen mode

Ushbu misollar yordamida siz har bir ma'lumot turining qanday ishlashini va qanday qiymatlar saqlashini ko'rishingiz mumkin. Har bir tur o'zining maxsus o'lchami va qiymat oralig'iga ega, bu esa dasturchilarga aniqroq va samaraliroq kod yozishga yordam beradi.

Top comments (0)