Thuta Learning
C#
BasicProgrammingအခြေခံ

Data Types

C#သင်ခန်းစာ 620 မိနစ်

ဒီခန်းပြီးရင် ဘာတတ်သွားမလဲ

  • Data Types ရဲ့core concept နဲ့runtime behavior ကိုရှင်းပြနိုင်ရန်
  • Normal, boundary နဲ့invalid cases ကိုကိုယ်တိုင်စမ်းနိုင်ရန်
  • Readable, type-safe နဲ့testable C# code ရေးနိုင်ရန်

ရိုးရိုးလေး ရှင်းပြမယ်

Data Types ကို ရိုးရိုးလေးနားလည်မယ်

C# data types တွေကို နားလည်ထားရင် program ထဲမှာ data ကို မှန်မှန်ကန်ကန်သိမ်းနိုင်ပါတယ်။ Data type မှန်မှ code မှန်မယ်၊ code မှန်မှ bug နည်းမယ်။ “Box ထဲကို ဘာထည့်မလဲ” ကို အစကတည်းက သတ်မှတ်ထားတာလို့ တွေးပါ။

Problem → Why → Solution

ပြဿနာ — ဘာကြောင့် ဒီ concept လိုတာလဲ

`double` ကိုfinancial equality အတွက်သုံးခြင်း သို့ narrowing conversion ကိုsilent လုပ်ခြင်းက data error ဖြစ်စေနိုင်ပါတယ်။

ဖြစ်လေ့ရှိတဲ့အမှား

Happy path တစ်ခု run အောင်ရုံဖြင့် code မှန်ကန်၊ maintainable နဲ့production-ready ဖြစ်ပြီဟုယူဆခြင်း။

Core Concept — အလုပ်လုပ်ပုံကိုနားလည်မယ်

Value types နဲ့reference types တွင် assignment/copy semantics ကွာပြီး numeric types တွင် range/precision ကွာပါတယ်။ Money အတွက် `decimal`, measurements အတွက် `double`, identifiers အတွက်string စသဖြင့် domain ကိုအခြေခံရွေးပြီး conversions, overflow နဲ့nullable state ကိုရှင်းလင်းထားပါ။

Mental Model
  1. Typed input
  2. C# expression + method
  3. CLR value / object state

Data Types ရဲ့core concept နဲ့runtime behavior ကိုရှင်းပြနိုင်ရန်

အဓိက Syntax / Pattern

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 နဲ့reference types တွင် assignment/copy semantics ကွာပြီး numeric types တွင် range/precision ကွာပါတယ်။ Money အတွက် `decimal`, measurements အတွက် `double`, identifiers အတွက်string စသဖြင့် domain ကိုအခြေခံရွေးပြီး conversions, overflow နဲ့nullable state ကိုရှင်းလင်းထားပါ။

Code ကို အဆင့်လိုက်ဖတ်မယ်

  1. Typed inputint quantity = 3; // ကိန်းပြည့်

    C# data types တွေကို နားလည်ထားရင် program ထဲမှာ data ကို မှန်မှန်ကန်ကန်သိမ်းနိုင်ပါတယ်။ Data type မှန်မှ code မှန်မယ်၊ code မှန်မှ bug နည်းမယ်။ “Box ထဲကို ဘာထည့်မလဲ” ကို အစကတည်းက သတ်မှတ်ထားတာလို့ တွေးပါ။

  2. C# expression + methodbool isAvailable = true; // true / false

    Value types နဲ့reference types တွင် assignment/copy semantics ကွာပြီး numeric types တွင် range/precision ကွာပါတယ်။ Money အတွက် `decimal`, measurements အတွက် `double`, identifiers အတွက်string စသဖြင့် domain ကိုအခြေခံရွေးပြီး conversions, overflow နဲ့nullable state ကိုရှင်းလင်းထားပါ။

  3. CLR value / object stateConsole.WriteLine($"Available: {isAvailable}");

    Numeric boundary, decimal calculation, nullable value နဲ့explicit conversion ပါသော sample တစ်ခုရေးပြီး `checked` context ကိုစမ်းပါ။

Execution Flow
  1. Typed input
  2. C# expression + method
  3. CLR value / object state

Success

Data Types ရဲ့core concept နဲ့runtime behavior ကိုရှင်းပြနိုင်ရန်

Failure

`double` ကိုfinancial equality အတွက်သုံးခြင်း သို့ narrowing conversion ကိုsilent လုပ်ခြင်းက data error ဖြစ်စေနိုင်ပါတယ်။

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

Real-world usage

လက်တွေ့ Project မှာ ဘယ်လိုသုံးမလဲ

Numeric boundary, decimal calculation, nullable value နဲ့explicit conversion ပါသော sample တစ်ခုရေးပြီး `checked` context ကိုစမ်းပါ။

Mini challenge

ကိုယ်တိုင်တည်ဆောက်ကြည့်ပါ

Numeric boundary, decimal calculation, nullable value နဲ့explicit conversion ပါသော sample တစ်ခုရေးပြီး `checked` context ကိုစမ်းပါ။

  • Example ကို copy မလုပ်ဘဲ ပြန်ရေးပါ
  • Normal input နဲ့ edge case စမ်းပါ
  • Run မလုပ်မီ compiler/output result ကိုခန့်မှန်းပါ
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}");

ရလဒ်: Data Types ရဲ့core concept နဲ့runtime behavior ကိုရှင်းပြနိုင်ရန်

အရိပ်အမြွက် ကြည့်ရန်

Numeric boundary, decimal calculation, nullable value နဲ့explicit conversion ပါသော sample တစ်ခုရေးပြီး `checked` context ကိုစမ်းပါ။

Quick Quiz 1 / 3

Data Types ရဲ့ အဓိကသဘောတရားက ဘာလဲ။

Quick Quiz 2 / 3

ဘယ်အမှားကို အရင်ဆုံးရှောင်သင့်လဲ။

Quick Quiz 3 / 3

Real project မှာ ဘယ်လိုအသုံးချသင့်လဲ။

ဒီသင်ခန်းစာမှာ မှတ်ထားရမယ့်အချက်များ

  • Typed input → C# expression + method → CLR value / object state
  • Value types နဲ့reference types တွင် assignment/copy semantics ကွာပြီး numeric types တွင် range/precision ကွာပါတယ်။ Money အတွက် `decimal`, measurements အတွက် `double`, identifiers အတွက်string စသဖြင့် domain ကိုအခြေခံရွေးပြီး conversions, overflow နဲ့nullable state ကိုရှင်းလင်းထားပါ။
  • `double` ကိုfinancial equality အတွက်သုံးခြင်း သို့ narrowing conversion ကိုsilent လုပ်ခြင်းက data error ဖြစ်စေနိုင်ပါတယ်။
  • Numeric boundary, decimal calculation, nullable value နဲ့explicit conversion ပါသော sample တစ်ခုရေးပြီး `checked` context ကိုစမ်းပါ။

C# documentation — Microsoft Learn

ဒီနေရာမှာ လူအများမှားတတ်တယ်

  • `double` ကိုfinancial equality အတွက်သုံးခြင်း သို့ narrowing conversion ကိုsilent လုပ်ခြင်းက data error ဖြစ်စေနိုင်ပါတယ်။
  • Happy path တစ်ခု run အောင်ရုံဖြင့် code မှန်ကန်၊ maintainable နဲ့production-ready ဖြစ်ပြီဟုယူဆခြင်း။

လက်တွေ့လေ့ကျင့်ခန်း

Numeric boundary, decimal calculation, nullable value နဲ့explicit conversion ပါသော sample တစ်ခုရေးပြီး `checked` context ကိုစမ်းပါ။

အလုပ်ဖြစ်ကြောင်း ဒီလိုသိမယ်: Laptop x 3 Price: 19.99 Available: True

နောက်ဆုံးပြင်ဆင်ရက်

Progress ကို ဤ browser (ဤစက်) တွင်သာ သိမ်းထားပါသည်။ အခြားစက်များနှင့် sync မလုပ်ပါ။

ဤသင်ခန်းစာတွင် အမှားတွေ့ပါက အကြောင်းကြားရန်သင့် email app ကို ဤသင်ခန်းစာလိပ်စာ ဖြည့်ပြီးသားဖြင့် ဖွင့်ပေးပါမည် — သင်ကိုယ်တိုင် ပို့မှသာ ပို့မည်ဖြစ်သည်။

Data Types | Thuta Learning