Re: [問題] nest dictionary 取值unbox的問題(已解決)

看板C_Sharp作者 (bliss)時間11年前 (2013/02/22 01:03), 編輯推噓0(003)
留言3則, 2人參與, 最新討論串1/1
參考了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
Dictionary<object, Dictionary<object, object>>
02/22 21:23, 1F

02/22 21:24, , 2F
這是我單純的想法,純粹使用[][]來取最後一個object
02/22 21:24, 2F

02/26 21:05, , 3F
可以 不過效果只有2層
02/26 21:05, 3F
文章代碼(AID): #1H9bDe7B (C_Sharp)