本文整理汇总了C#中HashTable.PrintValue方法的典型用法代码示例。如果您正苦于以下问题:C# HashTable.PrintValue方法的具体用法?C# HashTable.PrintValue怎么用?C# HashTable.PrintValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HashTable
的用法示例。
在下文中一共展示了HashTable.PrintValue方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
public static void Main()
{
var topCities = new HashTable<string, double>();
// Add(key, value)
topCities.Add("Tokyo", 36.9);
topCities.Add("Jakarta", 12.8);
topCities.Add("Seoul", 25.7);
topCities.Add("Beijing", 23.7);
topCities.Add("Shanghai", 21.7);
// foreach
foreach (var pair in topCities.OrderBy(p => -p.Value))
{
Console.WriteLine("{0, -8} -> {1}", pair.Key, pair.Value);
}
// Add already existing key
try
{
topCities.Add("Jakarta", 0);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
// Keys
Console.WriteLine("Keys: {0}", string.Join(", ", topCities.Keys));
// Count
Console.WriteLine("Number of key-value pairs: {0}", topCities.Count);
// Find(key)
topCities.PrintValue("Tokyo");
Console.WriteLine("Jakarta -> {0}", topCities.Find("Jakarta"));
// this[key]
Console.WriteLine("Beijing -> {0}", topCities["Beijing"]);
// ContainsKey(key)
Console.WriteLine("Hash table contains 'Delhi': {0}", topCities.ContainsKey("Delhi"));
// Remove(key)
topCities.Remove("Seoul");
Console.WriteLine("Remove 'Seoul'");
Console.WriteLine("Keys: {0}", string.Join(", ", topCities.Keys));
Console.WriteLine("Number of key-value pairs: {0}", topCities.Count);
// Remove non-existing
Console.WriteLine("Removing 'Sofia' -> {0}", topCities.Remove("Sofia"));
// Clear
topCities.Clear();
Console.WriteLine("Clear hash table");
Console.WriteLine("Number of key-value pairs: {0}", topCities.Count);
}