locked
retrieve hash value when the value is an object in vb.net RRS feed

  • Question

  • User1329437667 posted

    How do I retrieve a hash value when the value itself is an object.

    I am giving an example here

    dim ht as new hastable

    dim person as clsperson

    ht.add(0, new ("AAA", "16", "23425345")

    ht.add(1, new("BBB", "18", "464745756")

    person=ht(0)  '   Doesn't work for some reason, I get nothing for person, although I see hashtable has key, value pairs

    class clsperson

    private name as string

    private age as string

    private ssn as string

    public sub new(strname as string, strage as string, strssn as string)

    name=strname

    age=strage

    ssn=strssn

    end sub

    end class

     

    Tuesday, July 19, 2011 2:05 PM

Answers

  • User-1694870838 posted

    Hi,

    Please refer to  sample code:

    Hashtable h = new Hashtable(); 
    Object k = new Object(); // can be any type of object 
    String v = "My value"; 
    h
    [k] = v; 
    String value = (String)h[k]; 

    Best Regards,

    Damon

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, July 26, 2011 1:10 AM

All replies

  • Thursday, July 21, 2011 6:23 AM
  • User1329437667 posted

    Hi, Thanks for the response, before I submitted this post I looked at these sites but was not helpful to my situation. I have an object(containting multiple parameters) as value. I need to retrieve from Hash table variable.

    Thursday, July 21, 2011 10:42 AM
  • User-1694870838 posted

    Hi,

    Please refer to  sample code:

    Hashtable h = new Hashtable(); 
    Object k = new Object(); // can be any type of object 
    String v = "My value"; 
    h
    [k] = v; 
    String value = (String)h[k]; 

    Best Regards,

    Damon

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, July 26, 2011 1:10 AM