list that holds 2 values each
I want to have a way to store a dynamic amount of data, where each entry holds a string and an int. What is the best way to handle this?
I'm thinking along the lines of a 2d list, or if that's not possible, maybe just 2 lists where I use code to compare the values imbetween them (values stored at the same index)
30 Replies
record?
never seen that before
use a class if you want
doesn't matter
just anything that holds data
make it a class that represents that data
records are classes with equality comparison built in
I only got a single class I can use, so making it as a class is not possible unfortunately
make a new one?
don't understand
because I'm using C# as a scripting language, so everything has to go into a single class
if it doesn't go into that class, the entire script breaks
bogus
Ero#1111
REPL Result: Success
Result: List<DataWithTwoValues>
Compile: 574.882ms | Execution: 118.395ms | React with ❌ to remove this embed.
can you remove items from the list?
sure?
sorry I'm self taught and a complete noob when it comes to this stuff
hell, I just learned about lists a few months back
before that I was using arrays for everything
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
also if you learned about lists "a few months back", i'd expect you to know everything there is to know about them
like it's not that difficult
the method is even called
.Remove()
Why not use a dictionary?
Wait, the conversation is much longer than I expected 😅 I might have missed a bit of the discussion
ah. I heard of those but didn't look into that, so I'm not sure what they are
I tend to learn things as I need them so...
yeah this will def cause bad programming habits
Dictionaries are basically key-value pairs
You can set them to hold a string as key, and your int as value. So you'll have both at all times
new Dictionary<string, int>() { {"myKey", 1} }
or the other way around
new Dictionary<int, string>() { {1, "myValue" } }
that might be what I'm looking for
dude I was the same with learning any language. "I'll get to those when I need them" 🤣 I know it can work
uh yeah no my code is disgusting
I gave many aneurisms on my other programming project
my first time working on "dynamic" UI stuff where the user can create more items and data and containers
If you want to get your "values" all you do is call the dictionary:
myDict[1]
or myDict["myKey"]
the back end...
that's useful, I'll take a look
I do try to keep conventions and such, but I learn stuff when I need thenm
uh...
this is the backend
a triple layered list
actually, maybe I might wanna future-proof this
is there any way to store data according to a single key?
when I do SourcePawn, there is a way to assign variables to certain players, meaning each player has their own storage that you can access
I'd like to do something similar in C#
oh, I think I found something online:
Dictionary, with the variable being a list, and the key is the "player" - would that work?
locals!
no idea what that is
yeah you do, you're using multiple in that code
say what now
your names are all pretty bad
and you don't follow conventions
yeah they are I agree
but tbh I can't be bothered to rewrite the entire system, it's a unity app
it took me two months to finally get it working
and it works so...
kinda off-topic tho. I think I figured out how to do what I wanted to
dictionary with a list as the variable