Create a Dictionary with multiple keys and get value using one of keys

I want to create a Dictionary that have a multiple keys and when I want to get value using just one or more keys.

I tried :

        Dictionary<Tuple<int, string>, string> dictionary = new Dictionary<Tuple<int, string>, string>();

        var Key   =new Tuple<int,string>(1,"I1");
        var Value = "this is a value";

        dictionary.Add(Key, Value);

When I try to get value from the dictionary I Must / Should enter all the keys

Like this :

MessageBox.Show($"{dictionary[new Tuple<int, string>(1,"I1")]}");

But when I try to get value using just one of keys like this

MessageBox.Show($"{dictionary[new Tuple<int, string>(1,"I1")]}");

I got error, I know that this error happened cause dictionary need the full exist key to return a value.

So please anyone have any Idea about how can I create a Dictionary with multiple keys and when retrieving value using just one or more or all keys ?



Read more here: https://stackoverflow.com/questions/64944140/create-a-dictionary-with-multiple-keys-and-get-value-using-one-of-keys

Content Attribution

This content was originally published by X Dev at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: