本文整理汇总了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*/