0

So here's the important bits, I have a dictionary with a key and value

public Dictionary<int, string> MyDictionary = new Dictionary<int, string>(); 

I can add to it with...

SomeClass.MyDictionary.Add(intValue, stringValue); 

I can search the dictionary and retrieve stringValue with...

if (SomeClass.MyDictionary.ContainsKey(intValue)) { string DictValues; SomeClass.MyDictionary.TryGetValues(intValue, out DictValues); } 

My problem now is that I need something that can contain two keys, that I can search for independent of each other.

This is wrong, but I'm looking for something like

public Dictionary<int, int, string> MyDictionary = new Dictionary<int, int, string>(); SomeClass.MyDictionary.Add(intValue1, intValue2, stringValue); 

When i run

SomeClass.MyDictionary.ContainsKey(intValue) 

I want search both intValue1 and intValue2 independently of each other. Basically i need to know if intValue1 OR intValue2 exists in this "dictionary" so hashing them together to see if both exist isn't an option. Using a tuple is not an option because I can't use the Add() function (maybe there's another way to add to tuples? unlikely).

I tried to use an Arraylist but they only store a single object. So I thought I could put a Tuple inside but then i can't search for individual tuple items.

I would like to avoid using two dictionaries as intValue1 and intValue2 are also a key, value pair. I need to know that intValue1 and intValue2 are related. intValue2 could be another key, and it some instances it could be a value that i need.

5
  • 2
    Can you not use two dictionaries? Commented Jan 21, 2018 at 17:36
  • 3
    You could just add the string twice, once for each key. Commented Jan 21, 2018 at 17:36
  • What if both keys are contained? Commented Jan 21, 2018 at 17:40
  • If you're going to flag this as a duplicate, could you at least post the duplicate question? Everything I looked at can be solved by hashing key1 and key 2. I'm not searching for key1 AND key2, just Key1 OR Key2 Commented Jan 21, 2018 at 17:45
  • @AntonioAnonymous The large banner at the top of this question shows you the duplicate it is linked to. That gives you all you need. Commented Jan 21, 2018 at 19:30

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.