C
C#Relevant

❔ ✅ Choosing an appropriate data structure

So I have a list of objects and I want one in the list to be active and the rest to be inactive. I was thinking of using a Dictionary<Thing, bool> where the bool is if it's active or not. I guess this would work, but then I'd have to do something like myDict.FirstOrDefault(d => d.Value == true).Key which feels a little clunky
H
Henkypenky397d ago
active in your case is just a figure of speech how would one approach such a problem you can have the list, and have the first be the active one or the last one or you can add a property to the object to mark it as active there is no data structure where only 1 object is active, this is more like a personal thing you can also consider a queue with priority, where the highest priority is the active object, and having DequeNormal and DequePriority what i'm trying to say is you either explicitly say the object is the active, adding a property to the object, or you manipulate the data structure to your advantage and document what, where and why the "active" object is
R
Relevant397d ago
Well you just made me think of what is probably the obvious answer. To just have a MyThing activeThing field
H
Henkypenky397d ago
yes but you need to control that there CANNOT be 2 active objects at the same time as per your requirements
R
Relevant397d ago
right, so whatever is the activeThing is the one that is active
H
Henkypenky397d ago
and if you try to add another to a collection, whichever it might be, check if it's active or not and check against the collection aswell
R
Relevant397d ago
Yeah, true Thanks
H
Henkypenky397d ago
np
R
Relevant397d ago
!close
A
Accord396d ago
Closed! Looks like nothing has happened here. I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server
More Posts
❔ Saving User DataI have it set up through properties, but I'm having a lot of trouble with showing it on other forms Unsupported statement value type: Microsoft.DotNet.DesignTools.Client.CodeDom.CodeBodyTextStatementhttps://github.com/Jordan-Belfort-88/Audio-Player-1.0/blob/master/Audio%20Player/Form1.Designer.cs IAssert.Raises<> in xUnitI'm trying to create tests for certain events. However it seems that xUnit assumes that I use EventH❔ I have an API function and I want to know what exception it can throw. How can I do that?This is not said in the documentationAmbiguity between 2 things idk how to fixGot an error message all of a sudden saying this when everything was working perfect before so i und❔ Problem populating DatagridI'm trying to populate a datagrid where certain columns are populated with information that is read ❔ Avisynth script maker thingIm trying to make a script that creates AVS files for every file in a Directory based on a template.❔ How to work with Hwnd in c#I want to open programs using Process.Start but all those programs have empty MainWindowHandle and M❔ VS For Mac Code CoverageHas anyone figured out how to show which lines are covered after running unit tests in VS For Mac?✅ Run code in main thread after Task.Run completed?Hello, I have a long running void function that I execute in a separate thread by calling `Task.Run(❔ methodHello, If I create a method, does the method know about things in the Main method? Or am I supposed ❔ Project structure1. In my Solution there should be only 1 Project right? Unless its a big App 2. I started using fo❔ how to use EF6 in library with no dependancy injection and no startup.csI used EF core power tools to generate DB Context and reverse engineer the models. now I get an erro❔ HeadFirst Design PatternSo I started with this Book today. First problem starts with the Duck Project: and when he tests h✅ EqualityComparerHello, anyone know of this code work ? --> `EqualityComparer<ICollection<myclass>> .Default.Equals❔ error attaching script (unity)this error appears when trying to attach the script, does anyone know how to solve it?❔ i have an app that runs well on my pc but not on other pcsi have an app that runs well on my pc but on when i zip it and bring it to another pc the ui is all yield???```cs public IEnumerable<int> A() { for (int i = 0; i <= 10; i += 2) yield return i; } C# Data Table issuehttps://pastebin.com/DSHwSh0M based on this program, I need to set the values of the `Old PS A11Y S❔ Microsoft Graph SDK - Serializing objectsHello, I am currently working with Microsoft Graph API to work with the Planner. My goal is to backu