How to create a HashMap in C#

31,718

Solution 1

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.

Solution 2

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

Change the types string and object to whatever you need.

Share:
31,718
kez
Author by

kez

Currently looking for Full Time or Part Time Job that can work Remotely

Updated on July 09, 2022

Comments

  • kez
    kez almost 2 years

    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<>();
    
  • kez
    kez over 8 years
    that means I have to go for dictionary
  • Karan Hotwani
    Karan Hotwani over 7 years
    @Ian, could you explain the differences?
  • Ian
    Ian over 7 years