作者hello1988 (bliss)
看板C_Sharp
标题Re: [问题] nest dictionary 取值unbox的问题(已解决)
时间Fri Feb 22 01:03:32 2013
参考了2楼的方法终於改写出来了
推 s3748679:
http://ppt.cc/oRmE 测试环境: C#2010 express
public class Node : Dictionary<object,object> {
public object Data{set;get;}
public Node Add( object KEY ){
this.Add( KEY,new Node );
return this;
}
public Node this [object KEY] {
get{
object RESULT;
this.TryGetValue( KEY, out RESULT );
return RESULT;
}
}
}
使用范例
Node ND = new Node();
ND.Add("KEY1");
ND["KEY1"].Add("KEY2");
ND["KEY1"]["KEY2"].Data = "Test String";
Console.WriteLine(ND["KEY1"]["KEY2"].Data);
//out put : Test String
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 119.77.130.173
※ 编辑: hello1988 来自: 119.77.130.173 (02/22 01:16)
※ 编辑: hello1988 来自: 119.77.130.173 (02/22 01:19)
※ 编辑: hello1988 来自: 119.77.130.173 (02/22 01:20)
1F:→ soup514:Dictionary<object, Dictionary<object, object>> 02/22 21:23
2F:→ soup514:这是我单纯的想法,纯粹使用[][]来取最後一个object 02/22 21:24
3F:→ hello1988:可以 不过效果只有2层 02/26 21:05