Results 1 to 3 of 3

Thread: Looping a Collection/Hashtble

  1. #1

    Thread Starter
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913

    Looping a Collection/Hashtble

    anyone used hashtable collection class yet that can help me here..


    i have a dll that has a public Hashtable that holds some values of another class

    code to add to the hashtable
    Code:
    		UserProps clsProp = new UserProps();
    		clsProp.UserHandle = Handle;
    		clsProp.UserID = SockID;
    		colUsers.Add(clsProp.UserID, clsProp);
    anyone now how to loop through this collection and search for a specific .UserID?
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  2. #2
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    With hastables, its a little different. Normal collections, you could just use a foreach loop, but a hashtable requires you to get an enumeration property or method and enumerate thru the whole collection.

    Check the msdn docs, I remember seeing it.
    Dont gain the world and lose your soul

  3. #3

    Thread Starter
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    got it..didnt have to loop at al

    Code:
    object clsProp = colUsers[SockID];	// this returns an object
    			
    			// cast the object to the UserProps class
    			UserProps userproperties = (UserProps)clsProp;
    			return userproperties.UserHandle;
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width