A dictionary is a key-value pair, where the value is selected depending on the key. All keys are unique.
Now, if you want Dictionarywith 1 key and several types of values, you have several options:
should be used first Tuple
var dict = new Dictionary<KeyType, Tuple<string, string, bool, int>>()
Another is to use (with C # 4.0 and above):
var dict = new Dictionary<KeyType, dynamic>()
System.Dynamic.ExpandoObject may be of any type.
using System;
using System.Linq;
using System.Collections.Generic;
public class Test {
public static void Main(string[] args) {
dynamic d1 = new System.Dynamic.ExpandoObject();
var dict = new Dictionary<int, dynamic>();
dict[1] = d1;
dict[1].FooBar = "Aniket";
Console.WriteLine(dict[1].FooBar);
dict[1].FooBar = new {s1="Hello", s2="World", s3=10};
Console.WriteLine(dict[1].FooBar.s1);
Console.WriteLine(dict[1].FooBar.s3);
}
}
source
share