The right way
Declare a new type β a class or structure β that contains the values ββyou want to get by key. To taste, you can add ToString and other methods.
class Values { public int Id { get; private set; } public string DisplayName { get; private set; } public Values (int id, string displayName) { Id = id; DisplayName = displayName; } public override string ToString () { return string.Format("{0};{1}", Id, DisplayName); } } var dic = new Dictionary<string, Values>(); dic.Add("news", new Values(1, "ΠΠΎΠ²ΠΎΡΡΠΈ")); dic.Add("analitika", new Values(2, "ΠΠ½Π°Π»ΠΈΡΠΈΠΊΠ°")); Values val = dic["news"]; string str = val.ToString(); // "1;ΠΠΎΠ²ΠΎΡΡΠΈ"
Way of the future
In the next version of C # 7, the creation of simple types will be really simple (the syntax is not final).
class Values (int id, string displayName) { public int Id { get; } = id; public string DisplayName { get; } = displayName; }
Or even like this:
class Values (int Id, string DisplayName);
Well, already in C # 6, adding to the dictionary will be easier due to dictionary initializers. Instead of code above or this code:
var dic = new Dictionary<string, Values> { { "news", new Values(1, "ΠΠΎΠ²ΠΎΡΡΠΈ") }, { "analitika", new Values(2, "ΠΠ½Π°Π»ΠΈΡΠΈΠΊΠ°") }, };
you can write:
var dic = new Dictionary<string, Values> { ["news"] = new Values(1, "ΠΠΎΠ²ΠΎΡΡΠΈ"), [ "analitika"] = new Values(2, "ΠΠ½Π°Π»ΠΈΡΠΈΠΊΠ°"), };
Way for the lazy
Instead of declaring a new type, you can use the Tuple type.
var dic = new Dictionary<string, Tuple<int, string>>(); dic.Add("news", Tuple.Create(1, "ΠΠΎΠ²ΠΎΡΡΠΈ")); dic.Add("analitika", Tuple.Create(2, "ΠΠ½Π°Π»ΠΈΡΠΈΠΊΠ°")); Tuple<int, string> val = dic["news"]; string str = return string.Format("{0};{1}", val.Item0, val.Item1); // "1;ΠΠΎΠ²ΠΎΡΡΠΈ"