4

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
  • 28,341
  • 18
  • 134
  • 157
kez
  • 2,171
  • 8
  • 54
  • 111

2 Answers2

10

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
  • 29,380
  • 18
  • 66
  • 103
2
var myHashMap = new Dictionary<string,object>();

Change the types string and object to whatever you need.

Johnny Clara
  • 481
  • 6
  • 18