none
CSharp Equivalent of java.util.HashMap<Interger, Class<?>> using Visual Studio 2008 SP1 RRS feed

  • Question

  • Dear All,

    I am looking for CSharp Equivalent of java.util.HashMap<Interger, Class<?>> using Visual Studio 2008 SP1.

    I managed to find CSharp Equivalent of java.util.HashMap is Hashtable in .NET but HashMap<Interger, Class<?>> not the complete one.

    I hope someone will advise me to get it done.

    Thanks and best regards

    Monday, February 4, 2013 3:18 AM

Answers

  • Hi All,

    Thank you for all replies and seem like Dictionary is ok as shown below for the time being.

    // Synchronized in Java
    [MethodImpl(MethodImplOptions.Synchronized)]
    
    public static void initialiseClassList()
            {
                Dictionary<int, Customer> customers = new Dictionary<int, Customer>();
    
                Customer cust1 = new Customer(1, "Cust 1");
                Customer cust2 = new Customer(2, "Cust 2");
                Customer cust3 = new Customer(3, "Cust 3");
    
                customers.Add(cust1.ID, cust1);
                customers.Add(cust2.ID, cust2);
                customers.Add(cust3.ID, cust3);
    
                bool bRlt = customers.ContainsKey(1);
                bRlt = customers.Remove(1);
    
                foreach (KeyValuePair<int, Customer> custKeyVal in customers)
                {
                    Console.WriteLine(
                        "Customer ID: {0}, Name: {1}",
                        custKeyVal.Key,
                        custKeyVal.Value.Name);
                }
            }

    Best regards

    • Marked as answer by Mr Ko Ko Monday, February 4, 2013 8:14 AM
    Monday, February 4, 2013 8:14 AM

All replies

  • I'm not sure how the Java class is coded, but I suspect that a Dictionary(Of TKey, TValue) where TKey is type Integer would be functionaly equivelent.


    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

    Monday, February 4, 2013 3:25 AM
    Moderator
  • Try Hashtable or Dictionary in this manner: Dictionary<int, dynamic> or Dictionary<int, object> or Dictionary<int, Type>. It depends on how this collection is used.


    • Edited by Viorel_MVP Monday, February 4, 2013 8:12 AM
    Monday, February 4, 2013 8:08 AM
  • Hi All,

    Thank you for all replies and seem like Dictionary is ok as shown below for the time being.

    // Synchronized in Java
    [MethodImpl(MethodImplOptions.Synchronized)]
    
    public static void initialiseClassList()
            {
                Dictionary<int, Customer> customers = new Dictionary<int, Customer>();
    
                Customer cust1 = new Customer(1, "Cust 1");
                Customer cust2 = new Customer(2, "Cust 2");
                Customer cust3 = new Customer(3, "Cust 3");
    
                customers.Add(cust1.ID, cust1);
                customers.Add(cust2.ID, cust2);
                customers.Add(cust3.ID, cust3);
    
                bool bRlt = customers.ContainsKey(1);
                bRlt = customers.Remove(1);
    
                foreach (KeyValuePair<int, Customer> custKeyVal in customers)
                {
                    Console.WriteLine(
                        "Customer ID: {0}, Name: {1}",
                        custKeyVal.Key,
                        custKeyVal.Value.Name);
                }
            }

    Best regards

    • Marked as answer by Mr Ko Ko Monday, February 4, 2013 8:14 AM
    Monday, February 4, 2013 8:14 AM