-1

I have a dictionary with developers and studios , as dictionary<devid,Tuple<developer,Studio>> where devid is the ID, developer and studios are objectd.

Can this dictionaty have more than one tuple associated to the key? Eg

devid 12345 Developer 1 studio 1 devid 12345 Deveoper 1 studio 2 

Devid always corresponds to the same developer. So can key 12345 correspond to both studio 1 and studio 2 as different records by adding to this dictionary or can 1 key only have one combination of developer and studio?

3
  • 1
    Think of ways you could make Tuple<ulong, object> into many. Hint: arrays and lists are good ways of storing multiple items. Commented Dec 13, 2018 at 7:20
  • 1
    Why not declare it as Dictionary<ulong, List<Tuple<ulong, Object>>> then? Now eack ulong key corresponds to a collection (i.e. many) tuples. Commented Dec 13, 2018 at 7:21
  • Could you be looking for NameValueCollection, which allows duplicate keys? Commented Dec 13, 2018 at 7:26

2 Answers 2

1

You can use sample test case i have written for your purpose:

using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Rextester { public class Program { public static void Main(string[] args) { Dictionary<long, List<Tuple<object, Object>>> testDict = new Dictionary<long, List<Tuple<object, Object>>>(); testDict.Add(12345 , new List<Tuple<object, object>>(){ new Tuple<object, object>("developer1", "studio1"), new Tuple<object, object>("developer1", "studio2"), new Tuple<object, object>("developer1", "studio3") }); foreach (KeyValuePair<long, List<Tuple<object, Object>>> kvp in testDict) { Console.WriteLine("Key = {0}, Value = {1}", kvp.Key, kvp.Value); foreach(Tuple<object, Object> tuple in kvp.Value) { Console.WriteLine("Item1 = {0}, Item2 = {1}", tuple.Item1, tuple.Item2); } } } } } 
Sign up to request clarification or add additional context in comments.

Comments

-1

No, it can't. The mentioned NameValueCollection does not quite suits you, 'cause it represents a collection of pares. So you need either Dictionary<ulong, List<Tuple<ulong, object>> or even Dictionary<ulong, Dictionary<ulong, object>>

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.