IDictionary的操作
来源:互联网 发布:淘宝帐号买卖 编辑:程序博客网 时间:2024/05/17 07:06
//注test1是個對象包含Name和Type屬性及SS()方法
test1 value1;
IDictionary<string, test1> iDict = new Dictionary<string, test1>();
iDict["a1"] = new test1("aa1", "str");//第一種附值的方法
iDict.Add("a2", new test1("aa2", "int"));//第二種添加方法
Response.Write(iDict["a1"].Type + "<br/>" + iDict["a1"].Name + ";<br/>" + iDict["a2"].Type + iDict["a2"].Name);//第一種取值的方法
iDict["a2"] = new test1("ab2", "int2");
Response.Write("2:" + iDict["a2"].Type + iDict["a2"].Name);
Label1.Text = iDict["a2"].SS();
if (iDict.TryGetValue("a2", out value1))//第二種取值的方法
{
Response.Write("<br/>3:" + value1.Name);
}
else
{
Response.Write("the index is not exist");
}
if(iDict.ContainsKey("a3"))//檢查key是否存在
{
Response.Write("<br/>存在a1");
}
foreach (KeyValuePair<string, test1> KVP in iDict)//迭代取得該IDictionary
{
Response.Write("<br/>begin:" + KVP.Key + KVP.Value.Name);
}
ICollection<test1> IC = iDict.Values;//取得所有的值
foreach (test1 tt in IC)
{
Response.Write("<br/>end:" + tt.Type);
}
//test1[] id ={ new test1("dd1", "int4"), new test1("dd2", "int5") };
//foreach (test1 tt in id)
//{
// Response.Write("<br/>end2:" + tt.Name);
//}
iDict.Remove("a1");//移除key="a1"的值
ICollection<string> ICC = iDict.Keys;//取得所有的key
foreach (string K in ICC)
{
Response.Write("<br/>Key:" + K);
}
test1 value1;
IDictionary<string, test1> iDict = new Dictionary<string, test1>();
iDict["a1"] = new test1("aa1", "str");//第一種附值的方法
iDict.Add("a2", new test1("aa2", "int"));//第二種添加方法
Response.Write(iDict["a1"].Type + "<br/>" + iDict["a1"].Name + ";<br/>" + iDict["a2"].Type + iDict["a2"].Name);//第一種取值的方法
iDict["a2"] = new test1("ab2", "int2");
Response.Write("2:" + iDict["a2"].Type + iDict["a2"].Name);
Label1.Text = iDict["a2"].SS();
if (iDict.TryGetValue("a2", out value1))//第二種取值的方法
{
Response.Write("<br/>3:" + value1.Name);
}
else
{
Response.Write("the index is not exist");
}
if(iDict.ContainsKey("a3"))//檢查key是否存在
{
Response.Write("<br/>存在a1");
}
foreach (KeyValuePair<string, test1> KVP in iDict)//迭代取得該IDictionary
{
Response.Write("<br/>begin:" + KVP.Key + KVP.Value.Name);
}
ICollection<test1> IC = iDict.Values;//取得所有的值
foreach (test1 tt in IC)
{
Response.Write("<br/>end:" + tt.Type);
}
//test1[] id ={ new test1("dd1", "int4"), new test1("dd2", "int5") };
//foreach (test1 tt in id)
//{
// Response.Write("<br/>end2:" + tt.Name);
//}
iDict.Remove("a1");//移除key="a1"的值
ICollection<string> ICC = iDict.Keys;//取得所有的key
foreach (string K in ICC)
{
Response.Write("<br/>Key:" + K);
}
- IDictionary的操作
- [C++]IDictionary的用法
- c# IDictionary接口的应用
- IDictionary 泛型集合的应用
- 创建有root和子节点的IDictionary object
- 阐述集合类的接口(IEnumerable,IEnumerator,ICollection,IList,IDictionary)
- c#学习笔记对IEnumerable<T>,IDictionary<Tkey,TValue>,ICollection<T>,IList<T>的总结
- 序列化IDictionary 类型
- 实现IDictionary接口
- IDictionary与IDictionaryEnumerator
- wf中的IDictionary
- IDictionary 泛型接口
- C# 关键字集合,IDictionary
- IDictionary遍历删除
- IDictionary 序列化一定要实现父类实现了ISerializable接口的,子类也必须有序列化构造函数,否则反序列化时会出错。
- 遍历Hashtable、IDictionary、Dictionary<string, string>
- IDictionary<TKey,TValue>数据字典使用讲解
- 遍历Hashtable、IDictionary、Dictionary<string, string>
- 《那些年啊,那些事——一个程序员的奋斗史》——72
- awk 值排序
- [CSS Hack]解決IE6、IE7、IE8、Firefox的瀏覽器相容性問題!
- gridvveiw常用操作
- cookie
- IDictionary的操作
- WebService 测试窗体只能用于来自本地计算机的请求
- VC GDI+: error C2660: 'new' : function does not take 3 parameters
- Android重量级开发之--提高android启动速度研究
- linux内核驱动中_IO, _IOR, _IOW, _IOWR 宏的用法与解析
- 1D.10 年计算机系统结构重点实验室召开年终2008年总结会
- C语言读写操作总结
- 5种方式比较排序
- jquery load方法使用