ch1_09.cs
来自「《c#技术内幕代码》」· CS 代码 · 共 47 行
CS
47 行
using System;
using System.Collections;
class CH1_9 {
public static void Main()
{
// Create a hashtable with a default comparison operator
// and initially 10 elements.
Hashtable ht = new Hashtable(10);
// Add ten strings to the hashtable associated with a
// key value (integer).
ht.Add( 100, "Science");
ht.Add( 200, "Math");
ht.Add( 300, "English");
ht.Add( 400, "History");
ht.Add( 500, "Gym");
// How many elements does the table contain?
Console.WriteLine("The hashtable contains {0} elements", ht.Count);
// Does it contain the entry for Gym? How about Recess?
Console.WriteLine("The hashtable contains 500? {0}", ht.Contains(500));
Console.WriteLine("The hashtable contains 600? {0}", ht.Contains(600));
// What is the value for 400? 800?
Console.WriteLine("The value for 400 is {0}", ht[400]);
Console.WriteLine("The value for 800 is {0}", ht[800]);
// See if the values are null
if ( ht[400] == null )
Console.WriteLine( "Entry 400 is null" );
else
Console.WriteLine( "Entry 400 is NOT null" );
if ( ht[800] == null )
Console.WriteLine( "Entry 800 is null" );
else
Console.WriteLine( "Entry 800 is NOT null" );
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?