c# - How to display values in a dictionary? -
How do you list the values in a dictionary in which the key is a string and the value is a string array?
Dictionaries & lt; String, string []> Item = New Dictionary & lt; String, string []> (); String [] Products 1 = {"Item 12", "Item 13", "Item 14", "Item 15"}; String [] products2 = {"item 1", "item 2", "item 3", "item 4"}; String [] Products 3 = {"Item 12", "Item 22", "Item 23", "Item 42", "Item 52"}; item. Add ("Products 1", Products 1); item. Add ("Products 2", Products 2); item. Add ("Products 3", Products 3);
I would like to print the following:
products1: item12, item13, item14, item15 products2: item1, item2, item3, item4 products3: item12, The key to list only related items: item22, item23, item42, item52
string .join (",", item [key]);
To list all products and all items:
foreach (cheat keys in the item) {System.Console.WriteLine ("{ 0}: {1} ", key, string.joined (", ", item [key]); }
Comments
Post a Comment