Thuta Learning
C#
BasicProgrammingအခြေခံ

Variables

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

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

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

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

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

Variable ဆိုတာ data သိမ်းထားတဲ့ box လေးတစ်ခုလိုပါပဲ။ C# မှာ variable မကြေညာခင် data type ကို ပြောပေးရပါတယ်။ ဒါကြောင့် code ရေးနေချိန်ကတည်းက မှားနိုင်တဲ့ data type ပြဿနာတွေကို compiler က စစ်ပေးနိုင်ပါတယ်။

Problem → Why → Solution

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

Uninitialized/default value နဲ့valid domain value ကိုမခွဲခြင်းက zero, false နဲ့null bugs ဖြစ်စေပါတယ်။

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

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

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

Variable တစ်ခုမှာ name, compile-time type, scope, lifetime နဲ့current value ရှိပါတယ်။ `var` သည် dynamic type မဟုတ်ဘဲ initializer မှ compile time တွင်type inference လုပ်တာဖြစ်ပြီး `const`၊ nullable annotations နဲ့smallest useful scope ကိုရည်ရွယ်ချက်ရှိရှိသုံးပါ။

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

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

အဓိက Syntax / Pattern

csharp
string name = "Aung";
int age = 30;
double height = 5.8;
bool isStudent = false;

Console.WriteLine("Name: " + name);
Console.WriteLine($"Age: {age}");
Console.WriteLine($"Height: {height}");
Console.WriteLine($"Student: {isStudent}");

Variable တစ်ခုမှာ name, compile-time type, scope, lifetime နဲ့current value ရှိပါတယ်။ `var` သည် dynamic type မဟုတ်ဘဲ initializer မှ compile time တွင်type inference လုပ်တာဖြစ်ပြီး `const`၊ nullable annotations နဲ့smallest useful scope ကိုရည်ရွယ်ချက်ရှိရှိသုံးပါ။

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

  1. Typed inputstring name = "Aung";

    Variable ဆိုတာ data သိမ်းထားတဲ့ box လေးတစ်ခုလိုပါပဲ။ C# မှာ variable မကြေညာခင် data type ကို ပြောပေးရပါတယ်။ ဒါကြောင့် code ရေးနေချိန်ကတည်းက မှားနိုင်တဲ့ data type ပြဿနာတွေကို compiler က စစ်ပေးနိုင်ပါတယ်။

  2. C# expression + methodConsole.WriteLine("Name: " + name);

    Variable တစ်ခုမှာ name, compile-time type, scope, lifetime နဲ့current value ရှိပါတယ်။ `var` သည် dynamic type မဟုတ်ဘဲ initializer မှ compile time တွင်type inference လုပ်တာဖြစ်ပြီး `const`၊ nullable annotations နဲ့smallest useful scope ကိုရည်ရွယ်ချက်ရှိရှိသုံးပါ။

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

    User age ကိုstring အဖြစ်ဖတ်ပြီး `int.TryParse` ဖြင့်validate လုပ်ကာ success/failure branch နှစ်ခုလုံးစမ်းပါ။

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

Success

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

Failure

Uninitialized/default value နဲ့valid domain value ကိုမခွဲခြင်းက zero, false နဲ့null bugs ဖြစ်စေပါတယ်။

Variable ဆိုတာ data သိမ်းထားတဲ့ box လေးတစ်ခုလိုပါပဲ။ C# မှာ variable မကြေညာခင် data type ကို ပြောပေးရပါတယ်။ ဒါကြောင့် code ရေးနေချိန်ကတည်းက မှားနိုင်တဲ့ data type ပြဿနာတွေကို compiler က စစ်ပေးနိုင်ပါတယ်။

csharp
string name = "Aung";
int age = 30;
double height = 5.8;
bool isStudent = false;

Console.WriteLine("Name: " + name);
Console.WriteLine($"Age: {age}");
Console.WriteLine($"Height: {height}");
Console.WriteLine($"Student: {isStudent}");

ဒီ code က ဘာလုပ်တာလဲ

  • string က စာသားသိမ်းပါတယ်။
  • int က ကိန်းပြည့်သိမ်းပါတယ်။
  • double က ဒသမကိန်းသိမ်းပါတယ်။
  • bool က true သို့မဟုတ် false သိမ်းပါတယ်။
  • $"Age: {age}" က string interpolation ဖြစ်ပြီး variable value ကိုစာသားထဲထည့်ပြတာ ပိုသန့်ရှင်းပါတယ်။
You should see
Name: Aung Age: 30 Height: 5.8 Student: False

Info

⚠️ Common mistake

int age = "30"; လို့ရေးရင် error တက်ပါတယ်။ "30" က စာသားဖြစ်ပြီး 30 က ကိန်းဂဏန်းပါ။ Quote ထည့်မထည့်က data type ကိုပြောင်းသွားစေနိုင်ပါတယ်။

Real-world usage

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

User age ကိုstring အဖြစ်ဖတ်ပြီး `int.TryParse` ဖြင့်validate လုပ်ကာ success/failure branch နှစ်ခုလုံးစမ်းပါ။

Mini challenge

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

User age ကိုstring အဖြစ်ဖတ်ပြီး `int.TryParse` ဖြင့်validate လုပ်ကာ success/failure branch နှစ်ခုလုံးစမ်းပါ။

  • Example ကို copy မလုပ်ဘဲ ပြန်ရေးပါ
  • Normal input နဲ့ edge case စမ်းပါ
  • Run မလုပ်မီ compiler/output result ကိုခန့်မှန်းပါ
csharp
string name = "Aung";
int age = 30;
double height = 5.8;
bool isStudent = false;

Console.WriteLine("Name: " + name);
Console.WriteLine($"Age: {age}");
Console.WriteLine($"Height: {height}");
Console.WriteLine($"Student: {isStudent}");

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

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

User age ကိုstring အဖြစ်ဖတ်ပြီး `int.TryParse` ဖြင့်validate လုပ်ကာ success/failure branch နှစ်ခုလုံးစမ်းပါ။

Quick Quiz 1 / 3

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

Quick Quiz 2 / 3

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

Quick Quiz 3 / 3

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

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

  • Typed input → C# expression + method → CLR value / object state
  • Variable တစ်ခုမှာ name, compile-time type, scope, lifetime နဲ့current value ရှိပါတယ်။ `var` သည် dynamic type မဟုတ်ဘဲ initializer မှ compile time တွင်type inference လုပ်တာဖြစ်ပြီး `const`၊ nullable annotations နဲ့smallest useful scope ကိုရည်ရွယ်ချက်ရှိရှိသုံးပါ။
  • Uninitialized/default value နဲ့valid domain value ကိုမခွဲခြင်းက zero, false နဲ့null bugs ဖြစ်စေပါတယ်။
  • User age ကိုstring အဖြစ်ဖတ်ပြီး `int.TryParse` ဖြင့်validate လုပ်ကာ success/failure branch နှစ်ခုလုံးစမ်းပါ။

C# documentation — Microsoft Learn

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

  • Uninitialized/default value နဲ့valid domain value ကိုမခွဲခြင်းက zero, false နဲ့null bugs ဖြစ်စေပါတယ်။
  • Happy path တစ်ခု run အောင်ရုံဖြင့် code မှန်ကန်၊ maintainable နဲ့production-ready ဖြစ်ပြီဟုယူဆခြင်း။

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

User age ကိုstring အဖြစ်ဖတ်ပြီး `int.TryParse` ဖြင့်validate လုပ်ကာ success/failure branch နှစ်ခုလုံးစမ်းပါ။

အလုပ်ဖြစ်ကြောင်း ဒီလိုသိမယ်: Name: Aung Age: 30 Height: 5.8 Student: False

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

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

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

Variables | Thuta Learning