EN
C#/.NET - Java HashMap equivalent
1 points
In C#/.NET System.Collections.Generic.Dictionary
class is the most closest to Java java.util.HashMap
class.
xxxxxxxxxx
1
Dictionary<string, int> dictionary = new Dictionary<string, int>();
2
3
dictionary.Add("e", 1);
4
dictionary.Add("d", 3);
5
dictionary.Add("c", 2);
6
dictionary.Add("b", 5);
7
dictionary.Add("a", 4);
8
9
Console.WriteLine("Size: " + dictionary.Count + "\n");
10
11
foreach (KeyValuePair<string, int> entry in dictionary)
12
Console.WriteLine("key=" + entry.Key + ", value=" + entry.Value);
Output:
xxxxxxxxxx
1
Size: 5
2
3
key=e, value=1
4
key=d, value=3
5
key=c, value=2
6
key=b, value=5
7
key=a, value=4