2

I'm sure this is a thing that can be done, well I think so. I want something similar to a list of, but instead of an index of numbers for the index it has strings as the index. What I want to be able to do is store a list of names which then have values so for example:

Index: "Bill", Value: 34234
Index: "Hagrid", Value: 4523445

and so on.

I could of course just build a custom class, then have a list of that class, but I want to be able to do *.contains on the list, which you can't do with custom classes, you would have to instead loop through the list of and check each item if it matches. I more or less asking if something like the above exists in vb.net, I could of sworn I've seen something like it somewhere.

I run into this problem a lot and varies a lot, and I dont want to have to create 10 tiny little classes just for storing data.

2 Answers 2

2

This sounds like a good use of Dictionary(Of TKey, TValue)

You can store what you want like so:

Dim _dict As New Dictionary(Of String, Integer)()
_dict.Add("Bill", 34234)

and so on.

MSDN Link

Sign up to request clarification or add additional context in comments.

2 Comments

This is exactly what I was thinking of, I'll mark the answer in 7 minutes ha. I had read of these some years ago so I knew something existed that I needed. This will be really handy now that I think about it.
Your alternative to create a custom class is also a good idea as you could also implement your own equality comparer etc but this is just faster!
0

You want to use Dictionaries:

Dim myDict As New Dictionary(Of String, Integer)
myDict.Add("Bill", 34234)
myDict.Add("Hagrid", 4523445)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.