Dictionary<string, Tuple<string, List<string>>> kvp = new Dictionary<string, Tuple<string, List<string>>>();
string key = "key_Value";
string a_Value = "whatever";
List<string> ListOf_String = new List<string>();
string[] strArr = { "String_A", "String_B", "String_C" };
ListOf_String.AddRange(strArr);
Tuple<string, List<string>> tuple = new Tuple<string, List<string>>(a_Value, ListOf_String);
kvp.Add(key, tuple);
foreach (KeyValuePair<string, Tuple<string, List<string>>> keyValue in kvp)
{
//Do something with your nested items.
}
Dictionary<string, Tuple<string, List<string>>> kvp = new Dictionary<string, Tuple<string, List<string>>>();
List<string> ListOf_String = new List<string>();
ListOf_String.AddRange(new string[] { "String_A", "String_B", "String_C" });
kvp.Add("key_Value", new Tuple<string, List<string>>("whatever", ListOf_String));
foreach (KeyValuePair<string, Tuple<string, List<string>>> keyValue in kvp)
{
//Do something with your nested items.
}
Dictionary<string, Tuple<string, string, List<string>>> kvp = new Dictionary<string, Tuple<string, string, List<string>>>();
Dictionary<string, Tuple<string[], List<string>>> kvp = new Dictionary<string, Tuple<string[], List<string>>>();
No we don't have any specific reason .I just want to structure my codeWhy do you think either would be useful? A singleton is specifically so there can never be more than one instance of your type. Is there a reason to impose that restriction in this case? There are various reasons to use interfaces, including for testability. Are you planning on writing unit tests for this type? If not, do you see any other benefits to defining an interface? You'll be implementing instance members in a class in either case so you would need some benefit to one or the other to implement either.
var myDictionary = new Dictionary<string, Tuple<string, int, List<string>>>();
// ...
Console.WriteLine("Enter key:");
var key = Console.ReadLine();
if (!myDictionary.ContainsKey(key))
{
Console.WriteLine("Invalid key.");
}
else
{
var value = myDictionary[key];
Console.WriteLine("Value: {0}, {1}, {2}", value.Item1, value.Item2, string.Join("|", value.Item3));
}
var myDictionary = new Dictionary<string, Tuple<string, int, List<string>>>();
// ...
Console.WriteLine("Enter key:");
var key = Console.ReadLine();
if (myDictionary.TryGetValue(key, out var value))
{
Console.WriteLine("Value: {0}, {1}, {2}", value.Item1, value.Item2, string.Join("|", value.Item3));
}
else
{
Console.WriteLine("Invalid key.");
}
Dictionary<string, Tuple<string, int, List<string>>> myDictionary = new Dictionary<string, Tuple<string, int, List<string>>>();
myDictionary.Add("string A", new Tuple<string, int, List<string>>("string B", 1, new List<string> { "String C" }));
if (myDictionary.TryGetValue("string A", out var value))
{
Debug.WriteLine(string.Format("{0}, {1}, {2}", value.Item1, value.Item2, value.Item3[0]));
}
string B, 1, String C
using System.Diagnostics;
. String Format converts the values of the objects into strings and essentially makes them into another string. value.Item1; where value is the tuple in your dictionary and .Item1 if the first value, value.Item2 is your int and value.Item3 is your List<string> and its value is accessed but calling the first position in the list<string> by value.Item3[0] from the tuple's third item. if (myDictionary.TryGetValue("string A", out Tuple<string, int, List<string>> value))
class Foo
{
string Bar;
int Baz;
List<string> Bizz;
}
Dictionary<string, Foo> myData;