Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a HashMap in C# [closed]

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<>();
like image 764
kez Avatar asked Dec 15 '22 09:12

kez


2 Answers

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.

like image 175
Ian Avatar answered Dec 16 '22 22:12

Ian


var myHashMap = new Dictionary<string,object>();

Change the types string and object to whatever you need.

like image 37
Johnny Clara Avatar answered Dec 16 '22 22:12

Johnny Clara