C
Join ServerC#
help
❔ 2D Dictionary
BBoggo2/16/2023
i'm wondering if it would be possible to create a 2d Dictionary of sorts where it would look something like: Dictionary<key, Dictionary<key, value>>. Context is each server should have a dictionary of clients, with an associated tcpClient value.
RRotor2/16/2023
The rule of thumb that I've always followed is that you should start to wrap your anonymous data into classes at this point, as it's the same thing but with more compiler hints
RRotor2/16/2023
Perhaps you should instead model your data as a Dictionary of
Client
classes, with a tcpClient
propertyRRotor2/16/2023
record Client(TCPClient client, other properties ...);
var dict = new Dictionary<Client>{ ["client one"] = new Client(...) };
Console.WriteLine(dict["client one"].client);
RRotor2/16/2023
It's pretty much the same logic as with dictionaries except you get the benefit of giving names to your properties, being able to store multiple properties and having better exceptions
RRotor2/16/2023
If you've got a whole collection of
TCPClient
s per Client
I'd still recommend storing that collection as a property - again to make the code more self-documentingAamio2/16/2023
It might be much easier and clearer to just key your dictionary with a tuple.
So not
So not
Dict<TKey1, Dict<TKey2, TValue>>
but Dict<(TKey1, TKey2), TValue>
Aamio2/16/2023
But honestly that's more for quick stuff, Rotor is 100% right that you could and should make a "neater" model around this. Proper naming, type hierarchy that makes sense etc
AAccord2/17/2023
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.