本文整理匯總了C#中System.Collections.Hashtable.GetEnumerator方法的典型用法代碼示例。如果您正苦於以下問題:C# Hashtable.GetEnumerator方法的具體用法?C# Hashtable.GetEnumerator怎麽用?C# Hashtable.GetEnumerator使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Collections.Hashtable
的用法示例。
在下文中一共展示了Hashtable.GetEnumerator方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: Main
//引入命名空間
using System;
using System.Collections;
public class HashtableExample
{
public static void Main()
{
// Creates and initializes a new Hashtable.
Hashtable clouds = new Hashtable();
clouds.Add("Cirrus", "Castellanus");
clouds.Add("Cirrocumulus", "Stratiformis");
clouds.Add("Altostratus", "Radiatus");
clouds.Add("Stratocumulus", "Perlucidus");
clouds.Add("Stratus", "Fractus");
clouds.Add("Nimbostratus", "Pannus");
clouds.Add("Cumulus", "Humilis");
clouds.Add("Cumulonimbus", "Incus");
// Displays the keys and values of the Hashtable using GetEnumerator()
IDictionaryEnumerator denum = clouds.GetEnumerator();
DictionaryEntry dentry;
Console.WriteLine();
Console.WriteLine(" Cloud Type Variation");
Console.WriteLine(" -----------------------------");
while (denum.MoveNext())
{
dentry = (DictionaryEntry) denum.Current;
Console.WriteLine(" {0,-17}{1}", dentry.Key, dentry.Value);
}
Console.WriteLine();
// Displays the keys and values of the Hashtable using foreach statement
Console.WriteLine(" Cloud Type Variation");
Console.WriteLine(" -----------------------------");
foreach (DictionaryEntry de in clouds)
{
Console.WriteLine(" {0,-17}{1}", de.Key, de.Value);
}
Console.WriteLine();
}
}
// The program displays the following output to the console:
//
// Cloud Type Variation
// -----------------------------
// Cirrocumulus Stratiformis
// Stratocumulus Perlucidus
// Cirrus Castellanus
// Cumulus Humilis
// Nimbostratus Pannus
// Stratus Fractus
// Altostratus Radiatus
// Cumulonimbus Incus
//
// Cloud Type Variation
// -----------------------------
// Cirrocumulus Stratiformis
// Stratocumulus Perlucidus
// Cirrus Castellanus
// Cumulus Humilis
// Nimbostratus Pannus
// Stratus Fractus
// Altostratus Radiatus
// Cumulonimbus Incus*/