(Real-Life Example: Connected Device List, IMEI Lookup Dictionary, Packet Queue)”**
C# में Collections आपके पूरे backend system की रीढ़ हैं।
GPS Server, Billing System, ERP, API—
हर जगह collections का heavy use होता है।
हम आज सीखेंगे सबसे ज़्यादा इस्तेमाल होने वाले Collections:
✔ List<T>
✔ Dictionary<TKey, TValue>
✔ HashSet<T>
✔ Queue<T>
✔ Stack<T>
और साथ में Real-Life GPS Server Examples भी।
✔ Ordered
✔ Duplicate allowed
✔ Index based access
✔ Fast insert at tail
Example:
List<GPSDevice> devices = new();
devices.Add(new GPSDevice());
List<GPSDevice> ConnectedDevices = new();
हर नया device connect होता है → Add
Disconnect → Remove
सबसे powerful collection GPS system के लिए।
✔ Key से value 0.00001 सेकंड में मिलती है
✔ Duplicate key नहीं
✔ Perfect for IMEI lookup
Example:
Dictionary<string, GPSDevice> devices = new();
devices["861128068064267"] = new GPSDevice();
var device = devices[imei]; // fastest lookup
यह lookup List से 50-100x faster होता है।
क्योंकि हर packet में IMEI आता है →
उससे device ढूँढना ही सबसे ज्यादा operations होता है।
✔ No duplicates
✔ Fast membership checks
✔ Perfect for storing unique IMEIs, IPs, device types
Example:
HashSet<string> imeiSet = new();
imeiSet.Add("861128068064267");
imeiSet.Add("861128068064267"); // ignored
if(lastPackets.Contains(packetId)) return;
lastPackets.Add(packetId);
Perfect जब order maintain करना हो।
Example:
Queue<string> packets = new();
packets.Enqueue("pkt1");
packets.Enqueue("pkt2");
var p = packets.Dequeue(); // pkt1
Incoming packets fast आते हैं →
processor धीरे parse कर पाता है।
So architecture:
TCP Receive Thread → Queue → Parser Thread
Use:
packetQueue.Enqueue(packet);
Parser thread:
string pkt = packetQueue.Dequeue();
Server stable रहता है, कोई packet loss नहीं।
Example:
Stack<string> history = new();
history.Push("cmd1");
history.Push("cmd2");
history.Pop(); // cmd2
Commands भेजने का इतिहास:
Stack<string> cmdHistory = new();
cmdHistory.Push("SET_TIME");
cmdHistory.Push("RESTART");
Undo last command → Pop।
| Feature | Recommended Collection | क्यों? |
|---|---|---|
| Connected devices | List<GPSDevice> → या better → Dictionary | fast search needed |
| IMEI lookup | Dictionary<string, GPSDevice> | सबसे fast |
| Avoid duplicates | HashSet<string> | unique maintain |
| Packet buffering | Queue<string> | FIFO |
| Undo commands | Stack<string> | LIFO |
| Device logs | List<string> | ordered storage |
| Device groups | Dictionary<string, List<GPSDevice>> | mapping |
Dictionary<string, GPSDevice> Devices;
Queue<string> PacketQueue;
HashSet<string> ProcessedPacketIds;
This is industry-standard GPS backend pattern.
List<T> → कई items चाहिए, order चाहिए
Dictionary → कुछ key के through fast value चाहिए
HashSet → duplicates avoid करने हैं
Queue → sequential processing
Stack → सबसे last वाला item चाहिए
C# Collections आपके system को बनाते हैं:
✔ Fast
✔ Efficient
✔ Scalable
✔ Memory optimized
✔ GPS server friendly
✔ Professional architecture
GPS systems में इनका सही इस्तेमाल आपके server को
super-stable और lightning-fast बनाता है।
0 Comments
Thanks for Commenting on our blogs, we will revert back with answer of your query.
EmojiThanks & Regards
Sonu Yadav