This content originally appeared on DEV Community and was authored by islomAli99
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.
-
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
-
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
-
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
-
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
-
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
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
-
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
-
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
-
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
-
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
-
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
-
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
-
char
char
— bu 2 baytli bir belgini saqlaydi (Unicode kodlashda).
char letter = 'A';
Console.WriteLine(letter); // Natija: A
-
string
string
— bu Unicode belgilardan iborat matnni saqlaydi.
string greeting = "Salom, dunyo!";
Console.WriteLine(greeting); // Natija: Salom, dunyo!
-
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
-
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
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.
This content originally appeared on DEV Community and was authored by islomAli99
islomAli99 | Sciencx (2024-07-31T19:35:48+00:00) C# da Data tiplar haqida. Retrieved from https://www.scien.cx/2024/07/31/c-da-data-tiplar-haqida/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.