C
C#

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.
Rrotor_2/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 Perhaps you should instead model your data as a Dictionary of Client classes, with a tcpClient property
record Client(TCPClient client, other properties ...);

var dict = new Dictionary<Client>{ ["client one"] = new Client(...) };

Console.WriteLine(dict["client one"].client);
record Client(TCPClient client, other properties ...);

var dict = new Dictionary<Client>{ ["client one"] = new Client(...) };

Console.WriteLine(dict["client one"].client);
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 If you've got a whole collection of TCPClients per Client I'd still recommend storing that collection as a property - again to make the code more self-documenting
Aamio2/16/2023
It might be much easier and clearer to just key your dictionary with a tuple. So not Dict<TKey1, Dict<TKey2, TValue>> but Dict<(TKey1, TKey2), TValue> 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.

Looking for more? Join the community!

Want results from more Discord servers?
Add your server
Recommended Posts
❔ calculatorI want to write a function which returns if a string can be used as calculator input. The calculator❔ How to split dates?I have following: ```cpp var dateTime = DateTime.Parse("01.01.2023 0:00:00"); var dArr = new DateTim❔ Help with problem solvingI am currently learning C# and I think it's going quite well. Well, at least the syntax part. My big✅ Trying to trigger Azure Function with OpenApiSo right, never had an issue with this but now all of a sudden... (I might have done something wrong❔ Some advices about hosting API asp.netHello, I have a question but it's not about some code, it's more about how my system. should work S❔ Auto incremented Id not sequentialHello, I have an auto increment on an Id(integer) column on a database, however values are not seque❔ Can I display this with an extension in VS code? :cry:I hope there is a some extension for display 😦❔ Windows Form App shows nothingis there a reason why when i run the windows form app nothing that i have in the form.cs[Design} sho❔ HelpI dont know why or how the int addend1 is non existent if i literally created it in the public metho❔ Ownership-based permission system...?So, in my ASP.NET 7 app I have a system of user clubs. Each club can have a founder and members, andDifference between mapping controller directly with app.MapControllers & in app.UseEndpoint method ?I was trying to setup vue.js 3 with asp.net core api in the same project file. one of the problem ❔ I cant get jumping to workIk I am new to scripting but this one is just stupid. For the life of me, the jumping wont seem to w❔ Local Space Clamping Values IssuesOnly the minimum clamping values seem to work correctly, the maximum clamping values are catapulting❔ DebuggingHi I'm using docker compose to up .net application and I'm using Rider IDE. Is it possible to debug ✅ Can i put constraint on ctor in interfaceI know the name is kinda misleading, but i couldn't think of anything else. So can i have interface,❔ Assign Keycloak Roles to User Identity Roles in ASP.NET CoreI'm using OIDC to authenticate with keycloak and finally communicate with Azure. I did the configura❔ empty constructorwhat's the point of using empty constructor method like this❔ Alphabetic assign to numberIm pretty new to C# and i want to get 01 - a 02 - b 03 - c 04 - d .... and other