ex-09-18

来自「Programming Csharp Source Code(代码) Prog」· 代码 · 共 40 行

TXT
40
字号
// Example 09-18: Keys and Values collections

namespace Programming_CSharp
{
   using System;
   using System.Collections;
  
   // a simple class to store in the array
   public class Tester
   {
      static void Main()
      {
         // Create and initialize a new Hashtable.
         Hashtable hashTable = new Hashtable();
         hashTable.Add("000440312", "George Washington");
         hashTable.Add("000123933", "Abraham Lincoln");
         hashTable.Add("000145938", "John Galt");
         hashTable.Add("000773394", "Ayn Rand");

         // get the keys from the hashTable
         ICollection keys = hashTable.Keys;

         // get the values
         ICollection values = hashTable.Values;

         // iterate over the keys ICollection
         foreach(string key in keys)
         {
            Console.WriteLine("{0} ", key);
         }

         // iterate over the values collection
         foreach (string val in values)
         {
            Console.WriteLine("{0} ", val);
         }
      }
   }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?