6

I know we can create a HashMap in Java. But I want to create a HashMap in C# for my ASP.NET MVC project.

Is this possible to do? If yes, how?

In Java we can create a HashMap like this:

import java.util.HashMap;
//...
HashMap<Name, Value> myDictionary = new HashMap<>();
Matthias Braun
  • 32,039
  • 22
  • 142
  • 171
kez
  • 2,273
  • 9
  • 64
  • 123

2 Answers2

11

Look at Dictionary<key,value> in the System.Collections.Generic. It is the C# "parallel" (albeit having some differences, it is the closest to) of HashMap in Java.

Ian
  • 30,182
  • 19
  • 69
  • 107
2
var myHashMap = new Dictionary<string,object>();

Change the types string and object to whatever you need.

Johnny Clara
  • 481
  • 6
  • 18