switch statement က တန်ဖိုးတစ်ခုအပေါ်မူတည်ပြီး case များစွာထဲက တစ်ခုကိုရွေး run ပေးပါတယ်။ if...else if အများကြီးဆက်ရေးရမယ့်အခါ switch က code ကိုပိုဖတ်လွယ်စေပါတယ်။
csharp
string role = "editor";
switch (role)
{
case "admin":
Console.WriteLine("Full access");
break;
case "editor":
Console.WriteLine("Can create and edit content");
break;
case "viewer":
Console.WriteLine("Read only access");
break;
default:
Console.WriteLine("Unknown role");
break;
}သတိထားရမယ့်အချက်
caseတစ်ခုက value တစ်ခုနဲ့ match ဖြစ်ရင် အဲဒီ block ကို run ပါတယ်။breakက switch ထဲကနေထွက်ဖို့သုံးပါတယ်။defaultက ဘယ် case နဲ့မှမတူတဲ့အခါ run ပါတယ်။
You should see
Can create and edit content