ခေါင်းစဉ် 45 / 63 20 မိနစ်

Data Types (Part-5)

ဒီသင်ခန်းစာမှာ C# Program အတွင်း သိမ်းဆည်းမည့် Data အမျိုးအစားကို သတ်မှတ်ပေးသော Data Type များအကြောင်း လေ့လာသွားမည်ဖြစ်သည်။ int, long, float, double, decimal, char, string, bool နှင့် DateTime တို့၏ ကွာခြားချက်၊ အသုံးပြုပုံနှင့် အခြေအနေအလိုက် သင့်တော်သည့် Data Type ရွေးချယ်ပုံတို့ကို လက်တွေ့နမူနာများဖြင့် ရှင်းလင်းထားသည်။


13. Escape Sequences

String ထဲမှာ အထူးလုပ်ဆောင်ချက်အချို့ ထည့်သွင်းဖို့ Escape Sequence ကို အသုံးပြုနိုင်ပါတယ်။

စာကြောင်းပြောင်းခြင်း — \n
Console.WriteLine("Name: Aung Aung\nCourse: C# Basic");

Output—

Name: Aung Aung
Course: C# Basic
Tab နေရာခြားခြင်း — \t
Console.WriteLine("Name\tAge\tGrade");
Console.WriteLine("Aung\t18\tA");

Output—

Name    Age    Grade
Aung    18     A
Double Quotation Mark ထည့်ခြင်း — \"
Console.WriteLine("He said, \"Hello C#\"");

Output—

He said, "Hello C#"
Backslash ထည့်ခြင်း — \\
Console.WriteLine("C:\\Courses\\CSharp");

Output—

C:\Courses\CSharp

အသုံးများသော Escape Sequences—

Escape Sequenceလုပ်ဆောင်ချက်
\nစာကြောင်းအသစ်ပြောင်းခြင်း
\tTab Space ထည့်ခြင်း
\"Double Quotation Mark ထည့်ခြင်း
\\Backslash ထည့်ခြင်း

14. Verbatim String

File Path ကဲ့သို့ Backslash များစွာပါတဲ့ စာသားတွေမှာ String ရဲ့ရှေ့မှာ @ ထည့်ပြီး Verbatim String အဖြစ် ရေးနိုင်ပါတယ်။

ပုံမှန်ရေးသားပုံ—

string path = "C:\\Courses\\CSharp\\Lesson6";

Verbatim String ပုံစံ—

string path = @"C:\Courses\CSharp\Lesson6";

ပုံစံနှစ်ခုလုံးရဲ့ Output က—

C:\Courses\CSharp\Lesson6

ဖြစ်ပါတယ်။


Logical Data Type

15. bool Data Type

bool ကို အခြေအနေတစ်ခု မှန်၊ မမှန် သိမ်းဆည်းဖို့ အသုံးပြုပါတယ်။

bool မှာ Value နှစ်မျိုးပဲ ရှိပါတယ်။

true
false

နမူနာ—

bool isActive = true;
bool isDeleted = false;
bool hasPermission = true;

Output ပြသခြင်း—

bool isStudent = true;

Console.WriteLine($"Is Student: {isStudent}");

Output—

Is Student: True

bool ကို—

  • User Active ဖြစ်၊ မဖြစ်
  • Login ဝင်ထား၊ မထား
  • Payment ပြီး၊ မပြီး
  • Item ရှိ၊ မရှိ
  • Student Pass ဖြစ်၊ မဖြစ်

စတဲ့ အခြေအနေတွေ သိမ်းဖို့ အသုံးပြုနိုင်ပါတယ်။

int mark = 75;
bool isPassed = mark >= 40;

Console.WriteLine($"Passed: {isPassed}");

Output—

Passed: True

ဒီ Code မှာ mark >= 40 ရဲ့ ရလဒ်က မှန်တဲ့အတွက် isPassed ထဲမှာ true သိမ်းသွားပါတယ်။

Progress သိမ်းလိုပါက Login ဝင်ပါ။ Login မဝင်ဘဲလည်း ခေါင်းစဉ်အားလုံးကို လေ့လာနိုင်ပါသည်။