Data Types (Part-7)
ဒီသင်ခန်းစာမှာ C# Program အတွင်း သိမ်းဆည်းမည့် Data အမျိုးအစားကို သတ်မှတ်ပေးသော Data Type များအကြောင်း လေ့လာသွားမည်ဖြစ်သည်။ int, long, float, double, decimal, char, string, bool နှင့် DateTime တို့၏ ကွာခြားချက်၊ အသုံးပြုပုံနှင့် အခြေအနေအလိုက် သင့်တော်သည့် Data Type ရွေးချယ်ပုံတို့ကို လက်တွေ့နမူနာများဖြင့် ရှင်းလင်းထားပါသည်။
လက်တွေ့ Program
24. Student Information Program
Data Type အမျိုးမျိုးကို အသုံးပြုပြီး Student Information Program တစ်ခု ရေးကြည့်ရအောင်။
string studentName = "Aung Aung"; int studentAge = 18; char grade = 'A'; double averageMark = 85.5; decimal courseFee = 150000.00m; bool isActive = true; DateTime enrollmentDate = new DateTime(2026, 8, 1); Console.WriteLine("===== Student Information ====="); Console.WriteLine($"Name: {studentName}"); Console.WriteLine($"Age: {studentAge}"); Console.WriteLine($"Grade: {grade}"); Console.WriteLine($"Average Mark: {averageMark}"); Console.WriteLine($"Course Fee: {courseFee}"); Console.WriteLine($"Active: {isActive}"); Console.WriteLine($"Enrollment Date: {enrollmentDate:dd/MM/yyyy}"); Console.WriteLine("================================");
Output—
===== Student Information ===== Name: Aung Aung Age: 18 Grade: A Average Mark: 85.5 Course Fee: 150000.00 Active: True Enrollment Date: 01/08/2026 ================================
ဒီ Program မှာ—
-
အမည်အတွက်
string -
အသက်အတွက်
int -
Grade အတွက်
char -
ပျမ်းမျှအမှတ်အတွက်
double -
သင်တန်းကြေးအတွက်
decimal -
Active အခြေအနေအတွက်
bool -
စာရင်းသွင်းရက်အတွက်
DateTime
ကို အသုံးပြုထားပါတယ်။
25. Product Information Program
string productName = "Keyboard"; int quantity = 2; decimal unitPrice = 45000.50m; bool isInStock = true; DateTime createdDate = DateTime.Now; decimal totalAmount = unitPrice * quantity; Console.WriteLine("===== Product Information ====="); Console.WriteLine($"Product: {productName}"); Console.WriteLine($"Quantity: {quantity}"); Console.WriteLine($"Unit Price: {unitPrice}"); Console.WriteLine($"Total Amount: {totalAmount}"); Console.WriteLine($"In Stock: {isInStock}"); Console.WriteLine($"Created Date: {createdDate:dd/MM/yyyy}"); Console.WriteLine("================================");
လက်တွေ့လေ့ကျင့်ခန်း
လေ့ကျင့်ခန်း (1): Data Type ရွေးချယ်ပါ
အောက်ပါ Data များအတွက် သင့်တော်သော Data Type ကို ရွေးချယ်ပါ။
- Student Name
- Student Age
- Course Fee
- Grade
- Active Status
- Enrollment Date
- Average Mark
အဖြေ—
string studentName; int studentAge; decimal courseFee; char grade; bool isActive; DateTime enrollmentDate; double averageMark;
လေ့ကျင့်ခန်း (2): Error ရှာပါ
အောက်ပါ Code တွေမှာ Error ဖြစ်စေနိုင်တဲ့အချက်ကို ရှာပါ။
int price = 1500.50; char grade = "A"; float height = 5.7; decimal courseFee = 150000.50;
အဖြေ—
double price = 1500.50; char grade = 'A'; float height = 5.7f; decimal courseFee = 150000.50m;
ပြင်ထားတဲ့အချက်တွေက—
-
ဒဿမကိန်းဖြစ်တဲ့
priceကိုdoubleပြောင်းထားပါတယ်။ -
charValue ကို Single Quotation Marks နဲ့ ရေးထားပါတယ်။ -
floatValue နောက်မှာfထည့်ထားပါတယ်။ -
decimalValue နောက်မှာmထည့်ထားပါတယ်။
လေ့ကျင့်ခန်း (3): Personal Profile
အောက်ပါအချက်အလက်များကို သင့်တော်တဲ့ Data Type နဲ့ Variable များထဲ သိမ်းပြီး Console ပေါ်မှာ ပြသပါ။
- အမည်
- အသက်
- မြို့
- Grade
- ပျမ်းမျှအမှတ်
- ကျောင်းသားဖြစ်၊ မဖြစ်
- မွေးနေ့
နမူနာအဖြေ—
string name = "Su Su"; int age = 17; string city = "Mandalay"; char grade = 'A'; double averageMark = 88.5; bool isStudent = true; DateTime birthDate = new DateTime(2009, 5, 10); Console.WriteLine($"Name: {name}"); Console.WriteLine($"Age: {age}"); Console.WriteLine($"City: {city}"); Console.WriteLine($"Grade: {grade}"); Console.WriteLine($"Average Mark: {averageMark}"); Console.WriteLine($"Is Student: {isStudent}"); Console.WriteLine($"Birth Date: {birthDate:dd/MM/yyyy}");
လေ့ကျင့်ခန်း (4): Output ခန့်မှန်းပါ
အောက်ပါ Code ရဲ့ Output ကို ခန့်မှန်းပါ။
int firstValue = 10; int secondValue = 20; string firstText = "10"; string secondText = "20"; Console.WriteLine(firstValue + secondValue); Console.WriteLine(firstText + secondText);
အဖြေ—
30 1020
ပထမစာကြောင်းမှာ int နှစ်ခုကို ပေါင်းထားလို့ 30 ရပါတယ်။
ဒုတိယစာကြောင်းမှာ string နှစ်ခုကို ဆက်ထားလို့ 1020 ရပါတယ်။
လေ့ကျင့်ခန်း (5): Product Total
အောက်ပါအချက်အလက်တွေကို သင့်တော်တဲ့ Data Type နဲ့ သိမ်းပြီး Total Amount တွက်ပါ။
Product Name = Mouse Unit Price = 18500.50 Quantity = 3 In Stock = true
နမူနာအဖြေ—
string productName = "Mouse"; decimal unitPrice = 18500.50m; int quantity = 3; bool isInStock = true; decimal totalAmount = unitPrice * quantity; Console.WriteLine($"Product: {productName}"); Console.WriteLine($"Unit Price: {unitPrice}"); Console.WriteLine($"Quantity: {quantity}"); Console.WriteLine($"Total Amount: {totalAmount}"); Console.WriteLine($"In Stock: {isInStock}");
သင်ခန်းစာအနှစ်ချုပ်
ဒီသင်ခန်းစာမှာ—
- Data Type က Variable ထဲမှာ သိမ်းမယ့် Data အမျိုးအစားကို သတ်မှတ်ပေးကြောင်း
-
ကိန်းပြည့်အတွက်
intနဲ့ ကိန်းပြည့်အကြီးများအတွက်longအသုံးပြုနိုင်ကြောင်း -
ဒဿမကိန်းများအတွက်
float,double,decimalအသုံးပြုနိုင်ကြောင်း -
ငွေကြေးတန်ဖိုးများအတွက်
decimalကို အသုံးပြုသင့်ကြောင်း -
စာလုံးတစ်လုံးအတွက်
charနဲ့ စာသားအတွက်stringအသုံးပြုကြောင်း -
မှန်၊ မမှန်အခြေအနေများအတွက်
boolကို အသုံးပြုကြောင်း -
ရက်စွဲနဲ့ အချိန်များအတွက်
DateTimeကို အသုံးပြုကြောင်း - Data ရဲ့ သဘောသဘာဝအပေါ်မူတည်ပြီး သင့်တော်တဲ့ Data Type ကို ရွေးချယ်ရကြောင်း
တို့ကို လေ့လာခဲ့ပါတယ်။