C# data types တွေကို နားလည်ထားရင် program ထဲမှာ data ကို မှန်မှန်ကန်ကန်သိမ်းနိုင်ပါတယ်။ Data type မှန်မှ code မှန်မယ်၊ code မှန်မှ bug နည်းမယ်။ “Box ထဲကို ဘာထည့်မလဲ” ကို အစကတည်းက သတ်မှတ်ထားတာလို့ တွေးပါ။
csharp
int quantity = 3; // ကိန်းပြည့်
long population = 54000000L; // ကြီးတဲ့ကိန်းပြည့်
double price = 19.99; // ဒသမကိန်း
char grade = 'A'; // စာလုံးတစ်လုံး
bool isAvailable = true; // true / false
string product = "Laptop"; // စာသား
Console.WriteLine($"{product} x {quantity}");
Console.WriteLine($"Price: {price}");
Console.WriteLine($"Available: {isAvailable}");အဓိက သိထားရန်
- Value types —
int,double,char,boolစတဲ့ data ကို တိုက်ရိုက်သိမ်းတဲ့ type များပါ။ - Reference types —
string, arrays, classes စတာတွေပါ။ Object တည်နေရာကို reference အနေနဲ့ကိုင်ထားပါတယ်။ charမှာ single quote'A'သုံးပြီးstringမှာ double quote"Hello"သုံးပါတယ်။
You should see
Laptop x 3 Price: 19.99 Available: True