熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

HashTable類

2013-11-13 10:06:26  來源: .NET編程 

  //HashTable類表示一個鍵(Key)/值(Value)對的集合根據指定的鍵的哈希代碼來組織這些鍵/值對

  //示例:

  using System;

  using SystemCollectionsGeneric;

  using SystemText;

  using SystemCollections;

  using SystemData;

  namespace ConsoleApplication

  {

  public class ContractorTest

  {

  public static void Main()

  {

  Hashtable currencies = new Hashtable();

  currenciesAdd(US Dollar);

  currenciesAdd(Japan Yen);

  currenciesAdd(France Euro);

  ConsoleWrite(US Currency: {} currencies[US]);

  ConsoleReadLine();

  }

  }

  }

  //示例:

  using System;

  using SystemCollectionsGeneric;

  using SystemText;

  using SystemCollections;

  using SystemData;

  namespace ConsoleApplication

  {

  public class ContractorTest

  {

  public static void Main()

  {

  student stu = new student();

  stuStuid = ;

  stuStrname = zhangsan;

  student stu = new student();

  stuStuid = ;

  stuStrname = lisi;

  Hashtable ht = new Hashtable();

  htAdd(stuStuid stu);

  htAdd(stuStuid stu);

  //第一種方法遍歷集合中元素不通用

  //for (int i = ; i < htCount + ; i++)

  //{

  //    student stu = (student)ht[i];

  //    ConsoleWriteLine(stuStuidToString() + + stuStrname);

  //}

  //第二種方法遍歷集合中元素

  IDictionaryEnumerator ide = htGetEnumerator();

  while (ideMoveNext())

  {

  DictionaryEntry destu = (DictionaryEntry)ideCurrent;

  //ConsoleWriteLine(destuKeyToString());

  student stu = (student)destuValue;

  ConsoleWriteLine(stuStuid + + stuStrname);

  }

  ConsoleReadLine();

  }

  }


From:http://tw.wingwit.com/Article/program/net/201311/12574.html
    推薦文章
    Copyright © 2005-2013 電腦知識網 Computer Knowledge   All rights reserved.