ရိုးရိုးလေး ရှင်းပြမယ်
Collections (List) ကို ရိုးရိုးလေးနားလည်မယ်
List<T> သည် size ပြောင်းနိုင်တဲ့ collection ဖြစ်ပါတယ်။ Array က fixed-size ဖြစ်ပေမယ့် List မှာ item ထပ်ထည့်တာ၊ ဖျက်တာ၊ ရှာတာတွေ ပိုလွယ်ပါတယ်။ Real project တွေမှာ items မည်မျှရှိမလဲ မသိတဲ့အခါ List ကို အများကြီးသုံးပါတယ်။
Problem → Why → Solution
ပြဿနာ — ဘာကြောင့် ဒီ concept လိုတာလဲ
Internal mutable List ကိုတိုက်ရိုက်return လုပ်ခြင်းကcaller ကိုclass state ပျက်စေနိုင်ပါတယ်။
ဖြစ်လေ့ရှိတဲ့အမှား
Happy path တစ်ခု run အောင်ရုံဖြင့် code မှန်ကန်၊ maintainable နဲ့production-ready ဖြစ်ပြီဟုယူဆခြင်း။
Core Concept — အလုပ်လုပ်ပုံကိုနားလည်မယ်
`List<T>` သည်ordered, resizable generic collection ဖြစ်ပြီး index access, add/remove နဲ့enumeration ပေးပါတယ်။ Complexity, duplicate policy, capacity, reference elements နဲ့enumeration အတွင်းmutation ကိုစဉ်းစားပါ။
- Task / collection
- .NET API + pipeline
- Typed result / failure
Collections (List) ရဲ့core concept နဲ့runtime behavior ကိုရှင်းပြနိုင်ရန်
အဓိက Syntax / Pattern
using System;
using System.Collections.Generic;
class Program
{
static void Main(string[] args)
{
List<string> tasks = new List<string>();
tasks.Add("Learn C# basics");
tasks.Add("Practice methods");
tasks.Add("Build a mini project");
tasks.Remove("Practice methods");
foreach (string task in tasks)
{
Console.WriteLine(task);
}
}
}`List<T>` သည်ordered, resizable generic collection ဖြစ်ပြီး index access, add/remove နဲ့enumeration ပေးပါတယ်။ Complexity, duplicate policy, capacity, reference elements နဲ့enumeration အတွင်းmutation ကိုစဉ်းစားပါ။
Code ကို အဆင့်လိုက်ဖတ်မယ်
- Task / collection
using System;List<T> သည် size ပြောင်းနိုင်တဲ့ collection ဖြစ်ပါတယ်။ Array က fixed-size ဖြစ်ပေမယ့် List မှာ item ထပ်ထည့်တာ၊ ဖျက်တာ၊ ရှာတာတွေ ပိုလွယ်ပါတယ်။ Real project တွေမှာ items မည်မျှရှိမလဲ မသိတဲ့အခါ List ကို အများကြီးသုံးပါတယ်။
- .NET API + pipeline
tasks.Add("Practice methods");`List<T>` သည်ordered, resizable generic collection ဖြစ်ပြီး index access, add/remove နဲ့enumeration ပေးပါတယ်။ Complexity, duplicate policy, capacity, reference elements နဲ့enumeration အတွင်းmutation ကိုစဉ်းစားပါ။
- Typed result / failure
}Contact list တွင်Add, Find, Remove နဲ့copy/read-only exposure ကိုစမ်းပြီး empty/duplicate cases ထည့်ပါ။
- Task / collection
- .NET API + pipeline
- Typed result / failure
Success
Collections (List) ရဲ့core concept နဲ့runtime behavior ကိုရှင်းပြနိုင်ရန်
Failure
Internal mutable List ကိုတိုက်ရိုက်return လုပ်ခြင်းကcaller ကိုclass state ပျက်စေနိုင်ပါတယ်။
List<T> သည် size ပြောင်းနိုင်တဲ့ collection ဖြစ်ပါတယ်။ Array က fixed-size ဖြစ်ပေမယ့် List မှာ item ထပ်ထည့်တာ၊ ဖျက်တာ၊ ရှာတာတွေ ပိုလွယ်ပါတယ်။ Real project တွေမှာ items မည်မျှရှိမလဲ မသိတဲ့အခါ List ကို အများကြီးသုံးပါတယ်။
using System;
using System.Collections.Generic;
class Program
{
static void Main(string[] args)
{
List<string> tasks = new List<string>();
tasks.Add("Learn C# basics");
tasks.Add("Practice methods");
tasks.Add("Build a mini project");
tasks.Remove("Practice methods");
foreach (string task in tasks)
{
Console.WriteLine(task);
}
}
}ဒီ code မှာ သင်ယူရမယ့်အချက်
using System.Collections.Generic;ထည့်မှList<T>သုံးနိုင်ပါတယ်။Add()က item ထည့်ပါတယ်။Remove()က item ဖျက်ပါတယ်။foreachနဲ့ list ထဲက item တိုင်းကို loop လုပ်ပါတယ်။
Learn C# basics Build a mini projectReal-world usage
လက်တွေ့ Project မှာ ဘယ်လိုသုံးမလဲ
Contact list တွင်Add, Find, Remove နဲ့copy/read-only exposure ကိုစမ်းပြီး empty/duplicate cases ထည့်ပါ။
Mini challenge
ကိုယ်တိုင်တည်ဆောက်ကြည့်ပါ
Contact list တွင်Add, Find, Remove နဲ့copy/read-only exposure ကိုစမ်းပြီး empty/duplicate cases ထည့်ပါ။
- Example ကို copy မလုပ်ဘဲ ပြန်ရေးပါ
- Normal input နဲ့ edge case စမ်းပါ
- Run မလုပ်မီ compiler/output result ကိုခန့်မှန်းပါ
using System;
using System.Collections.Generic;
class Program
{
static void Main(string[] args)
{
List<string> tasks = new List<string>();
tasks.Add("Learn C# basics");
tasks.Add("Practice methods");
tasks.Add("Build a mini project");
tasks.Remove("Practice methods");
foreach (string task in tasks)
{
Console.WriteLine(task);
}
}
}ရလဒ်: Collections (List) ရဲ့core concept နဲ့runtime behavior ကိုရှင်းပြနိုင်ရန်
အရိပ်အမြွက် ကြည့်ရန်
Contact list တွင်Add, Find, Remove နဲ့copy/read-only exposure ကိုစမ်းပြီး empty/duplicate cases ထည့်ပါ။
Quick Quiz 1 / 3
Quick Quiz 2 / 3
Quick Quiz 3 / 3
ဒီသင်ခန်းစာမှာ မှတ်ထားရမယ့်အချက်များ
- Task / collection → .NET API + pipeline → Typed result / failure
- `List<T>` သည်ordered, resizable generic collection ဖြစ်ပြီး index access, add/remove နဲ့enumeration ပေးပါတယ်။ Complexity, duplicate policy, capacity, reference elements နဲ့enumeration အတွင်းmutation ကိုစဉ်းစားပါ။
- Internal mutable List ကိုတိုက်ရိုက်return လုပ်ခြင်းကcaller ကိုclass state ပျက်စေနိုင်ပါတယ်။
- Contact list တွင်Add, Find, Remove နဲ့copy/read-only exposure ကိုစမ်းပြီး empty/duplicate cases ထည့်ပါ။
Collections and data structures — Microsoft Learn