Re: [問題] nest dictionary 取值unbox的問題(已解決)
參考了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)
→
02/22 21:23, , 1F
02/22 21:23, 1F
→
02/22 21:24, , 2F
02/22 21:24, 2F
→
02/26 21:05, , 3F
02/26 21:05, 3F