By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,665 Members | 1,761 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,665 IT Pros & Developers. It's quick & easy.

data structure

P: n/a

Hello,
I would like to use a two ways data structure. Such as hash table that
will provide me a mapping but to both sides and not only one side as it
is in hash table. Is there such data structure in c#?
Thank u!
*** Sent via Developersdex http://www.developersdex.com ***
Jul 20 '08 #1
Share this Question
Share on Google+
3 Replies


P: n/a
On Jul 20, 3:45*pm, csharpula csharp <csharp...@yahoo.comwrote:
Hello,
I would like to use a two ways data structure. Such as hash table that
will provide me a mapping but to both sides and not only one side as it
is in hash table. Is there such data structure in c#?
No, but there's nothing to stop you from using two Dictionary
instances together to achieve the same effect, and even wrapping them
in your own class to ensure that they always remain consistent.
Jul 20 '08 #2

P: n/a

And how will I bound the two dictionaries for this purpose?
How to implement this?

Thanks.
*** Sent via Developersdex http://www.developersdex.com ***
Jul 20 '08 #3

P: n/a
csharpula csharp wrote:
And how will I bound the two dictionaries for this purpose?
How to implement this?

Thanks.
You just put two dictionaries in a class, and when you add an item, add
it to both dictionaries.

Starting point:

class DoubleDictionary<Key, Value{

private Dictionary<Key, Value_values = new Dictionary<Key, Value>();
private Dictionary<Value, Key_keys = new Dictionary<Value, Key>();

public void Add(Key key, Value value) {
_values.Add(key, value);
_keys.Add(value, key);
}

public Value GetByKey(Key key) {
return _values[key];
}

public Key GetByValue(Value value) {
return _keys[value];
}

}

--
Göran Andersson
_____
http://www.guffa.com
Jul 20 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.