这个Hashtable好象很复杂,有没有简单一点的能记录几个键值对的集合类啊
解决方案 »
- C# 网页中 怎么用用手机号和邮件都可以做登录用户名
- 求助:System.Numeric.BigInteger 不可访问,因为他受保护级别限制
- 如何将虚拟表中的字段插入到水晶报表中??
- 点击radioButton隐藏panel控件的c#代码??
- 求一个判断Sql语句是否正确的函数?
- 请教下大家,找图的思路(也就是在屏幕上找指定的图片,返回坐标)
- ArrayList A 和ArrayList B,如果A和B中有重复的项,则删除掉,留下唯一一条,此语句何解?
- datetimepicker.value取出的年份是2位的啊
- winform mdi 在子窗体 B里面 切换成子窗体C
- 请问那里有.net beta2 的免费下载?
- 定制控件问题,难啊!
- 急,在线等
{
myHT = new System.Collections.Hashtable();
myHT.Add("哈哈","呵呵");
}这样就搞定了,我把他搞成局部变量了,我哭,我的一百分哪
能给我个windows服务的例子吗?想学习。
using System;
using System.Collections;
public class SamplesHashtable { public static void Main() { // Creates and initializes a new Hashtable.
Hashtable myHT = new Hashtable();
myHT.Add( 0, "zero" );
myHT.Add( 1, "one" );
myHT.Add( 2, "two" );
myHT.Add( 3, "three" );
myHT.Add( 4, "four" ); // Displays the values of the Hashtable.
Console.WriteLine( "The Hashtable contains the following values:" );
PrintIndexAndKeysAndValues( myHT ); // Searches for a specific key.
int myKey = 2;
Console.WriteLine( "The key \"{0}\" is {1}.", myKey, myHT.ContainsKey( myKey ) ? "in the Hashtable" : "NOT in the Hashtable" );
myKey = 6;
Console.WriteLine( "The key \"{0}\" is {1}.", myKey, myHT.ContainsKey( myKey ) ? "in the Hashtable" : "NOT in the Hashtable" ); // Searches for a specific value.
String myValue = "three";
Console.WriteLine( "The value \"{0}\" is {1}.", myValue, myHT.ContainsValue( myValue ) ? "in the Hashtable" : "NOT in the Hashtable" );
myValue = "nine";
Console.WriteLine( "The value \"{0}\" is {1}.", myValue, myHT.ContainsValue( myValue ) ? "in the Hashtable" : "NOT in the Hashtable" );
}
public static void PrintIndexAndKeysAndValues( Hashtable myList ) {
IDictionaryEnumerator myEnumerator = myList.GetEnumerator();
int i = 0;
Console.WriteLine( "\t-INDEX-\t-KEY-\t-VALUE-" );
while ( myEnumerator.MoveNext() )
Console.WriteLine( "\t[{0}]:\t{1}\t{2}", i++, myEnumerator.Key, myEnumerator.Value );
Console.WriteLine();
}
}
/*
This code produces the following output.The Hashtable contains the following values:
-INDEX- -KEY- -VALUE-
[0]: 4 four
[1]: 3 three
[2]: 2 two
[3]: 1 one
[4]: 0 zeroThe key "2" is in the Hashtable.
The key "6" is NOT in the Hashtable.
The value "three" is in the Hashtable.
The value "nine" is NOT in the Hashtable.
*/