Forked from ishu3101/multiple_value_dictionary.cs
Created
September 24, 2018 18:12
-
-
Save h26k2/7e50b28e0a28b622fda27d34a101f4f8 to your computer and use it in GitHub Desktop.
Dictionary with Single Key and Multiple Values Example in C#. See https://repl.it/CY3S/1 to run example code online.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
class MainClass { | |
public static void Main (string[] args) { | |
Dictionary<string, List<String>> map = new Dictionary<string, List<String>>(); | |
// create list one and store values | |
List<string> valSetOne = new List<string>(); | |
valSetOne.Add("Apple"); | |
valSetOne.Add("Aeroplane"); | |
// create list two and store values | |
List<String> valSetTwo = new List<String>(); | |
valSetTwo.Add("Bat"); | |
valSetTwo.Add("Banana"); | |
// create list three and store values | |
List<String> valSetThree = new List<String>(); | |
valSetThree.Add("Cat"); | |
valSetThree.Add("Car"); | |
// add values into map | |
map.Add("A", valSetOne); | |
map.Add("B", valSetTwo); | |
map.Add("C", valSetThree); | |
// iterate and display values | |
foreach(KeyValuePair<string, List<string>> kvp in map){ | |
foreach(string value in kvp.Value){ | |
Console.WriteLine("Key = {0}, Value = {1}", kvp.Key, value); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment