Dictionary access to data is very convenient.

Dictionary<string, int> dic = new Dictionary<string, int>(); dic.Add("Аналитика,0"); dic.Add("Новости,1"); var temp = dic["Новости"]; // ΠŸΠΎΠ»ΡƒΡ‡Π°Π΅ΠΌ 1 

How to make it so that I can shove three parameters into Dictinary and so that I can also access variables easily?

 Dictionary<string,string, int> dic = new Dictionary<string,string, int>(); dic.Add("Аналитика", "analitika",0); dic.Add("Новости","news",1); var temp = dic["analitika"];// На Π²Ρ‹Ρ…ΠΎΠ΄Π΅ 0;Аналитика 

    1 answer 1

    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;Новости"