Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 173
  • Last Modified:

Using more than one key in a collection

I have a collection but need to get to the correct record by more than one key. For example: I have a collection of users where the key is UserID but I need to also reach a record if I have the UserName. Is there a way without looping throught the whole thing?
0
adinas
Asked:
adinas
1 Solution
 
mcriderCommented:
I think that the only way to do this without looping would be to keep two collections of the same information... One keyed by UserID and the other keyed by UserName...


Cheers!®©
0
 
woodsrrCommented:
You can do a look up collection.  This would require two collections. One main collection with the UserId as the key and a second collection with the UserName as the key.  The second collection has the UserId as it's only value, which you use to look up in the first collection.   Could be done with arrays also.
0
 
mcriderCommented:
woodsrr, "This would require two collections..."

What I said... ;-)
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
VBGuruCommented:
adinas,
I don't agree with you. Even when you specify the key value, the internal implemenation of the collection will/ should have implemented the search algo. So in  your case it is better you implement the search for userId rather than username.
or else you have a funcion which generate a unique key value given a username or userID and use that as the key value. In this case, the function should be able to get the username/id from db you if you spacify anyone.
0
 
adinasAuthor Commented:
Well, using two collections is what I planed to use if there was no solution. I don't understand why collections can't be as versetile as a database table.

Thanks anyways.
0
 
mcriderCommented:
Thanks for the points...

>>I don't understand why collections can't be as versetile as a database table.

Blame Microsoft ;-)


Cheers!®©
0
 
adinasAuthor Commented:
why, do other languages have better "collections"?
0
 
mcriderCommented:
Better language developers?? ;-)
0
 
adinasAuthor Commented:
ha ha

:-)
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now