-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?

Tshilidzi Mudau
  • 7,373
  • 6
  • 36
  • 49
John Abel
  • 271
  • 6
  • 20
  • 1
    Think of ways you could make `Tuple` into many. Hint: arrays and lists are good ways of storing multiple items. – ProgrammingLlama Dec 13 '18 at 07:20
  • 1
    Why not declare it as `Dictionary>>` then? Now eack `ulong` key corresponds to a collection (i.e. *many*) tuples. – Dmitry Bychenko Dec 13 '18 at 07:21
  • Could you be looking for [NameValueCollection](https://stackoverflow.com/questions/3001108/namevaluecollection-vs-dictionarystring-string), which allows duplicate keys? – John Wu Dec 13 '18 at 07:26

2 Answers2

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);
                }
            }
        }
    }
}
Serhat Oz
  • 788
  • 8
  • 12
-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>>