Store Object to Hashtable - CSharp Collection

CSharp examples for Collection:Hashtable

Description

Store Object to Hashtable

Demo Code

using System;//from w ww  . j a  v  a  2  s . co  m
using System.Collections;
struct Person {
   public Person( string f, string l ) { FName = f; LName = l; }
   public string LName;
   public string FName;
}
public class HashtableTest {
   public static void Main( ) {
      Hashtable People = new Hashtable( );

      People.Add( "S", new Person( "J", "S" ) );
      People.Add( "J", new Person( "D", "J" ) );
      People.Add( "P", new Person( "B", "P" ) );

      Person p = (Person)People["S"];
      Console.WriteLine("{0} {1}", p.FName, p.LName );
   }
}

Result


Related Tutorials