C# में Collections सबसे powerful tools हैं।
Real projects—जैसे GPS Server, Billing Software, School System, E-Commerce, Gameplay—
99% जगह collections use होते हैं।
Collection = ऐसा container जो multiple objects को store करता है।
आज हम सबसे useful 3 collections समझेंगे:
List
Dictionary
Queue
और हर एक को आपके GPS Server के Real-Life Examples से explain करेंगे।
List एक dynamic array है।
आप इसमें elements add/remove कर सकते हैं।
List<string> names = new List<string>();
names.Add("Rahul");
names.Add("Amit");
आपका GPS TCP server एक time में
1000–2000 devices connect रख सकता है।
आपको एक जगह list रखनी होती है:
List<GPSDevice> ConnectedDevices = new List<GPSDevice>();
जब नया device connect हो:
ConnectedDevices.Add(device);
Device disconnect:
ConnectedDevices.Remove(device);
✔ Order maintain करता है
✔ Fast add/remove
✔ Iterate करना आसान
Cart items:
List<CartItem> cart = new List<CartItem>();
Students of Class 9:
List<Student> class9 = new List<Student>();
किसी चीज़ को unique key से access करना हो
तो Dictionary सबसे best।
इसे ऐसे समझें:
PhoneBook: Name → Phone Number
हर GPS device की unique key = IMEI होती है।
इसलिए dictionary best है:
Dictionary<string, GPSDevice> Devices = new Dictionary<string, GPSDevice>();
Devices[device.IMEI] = device;
var d = Devices["861128068064267"];
✔ IMEI से तेज़ lookup
✔ कोई loop नहीं
✔ Real-time servers में fastest performance
✔ Thousands devices आसानी से handle
Large-scale GPS trackers हमेशा Dictionary का use करते हैं।
ProductCode → ProductDetail
Dictionary<string, Product> products;
RollNo → Student
Dictionary<int, Student> school;
Queue ऐसा collection है जहां:
जो सबसे पहले आएगा,
वही सबसे पहले जाएगा
बिल्कुल ticket counter की तरह।
एक GPS device बार-बार packets भेजता है:
location
heartbeat
alarm
LBS
status
इन packets को FIFO queue में डालकर process कर सकते हैं।
Queue<string> packetQueue = new Queue<string>();
Add packet:
packetQueue.Enqueue(packet);
Process packet:
string next = packetQueue.Dequeue();
Queue ensures:
पहले आया packet पहले process हो।
Printing invoices one by one
→ Queue
Player actions are in queue:
Move
Attack
Jump
Order maintained by Queue.
| Use Case | Best Collection |
|---|---|
| Multiple items store करना | List |
| IMEI जैसी unique key से fast access | Dictionary |
| FIFO order maintain करना | Queue |
| No duplicates चाहिए | HashSet |
| Sorted data चाहिए | SortedList |
C# collections हर बड़े project की backbone हैं:
List → Connected devices
Dictionary → IMEI lookup system
Queue → Packet processing
HashSet → Duplicate avoid
SortedList → Ordered data
GPS servers, web apps, games—
हर जगह collections का भारी use है।
आप जितना clean collection use करोगे,
आपका code उतना fast और scalable बनेगा।
0 Comments
Thanks for Commenting on our blogs, we will revert back with answer of your query.
EmojiThanks & Regards
Sonu Yadav