[問題] Dictinoary<string, Dictionary<string,c

看板C_Sharp作者 (ioptt)時間8年前 (2016/03/31 15:16), 編輯推噓1(105)
留言6則, 2人參與, 最新討論串1/1
各位前輩, 想請問 class1(string name, string type, string comt) Dictionary<string(module), Dictionary<string(name), class1>> 的問題 我需要從檔案中讀取資料, 想存在如上的資料結構裡, 以方便做search 由於檔案的內容長度不一定, 所以想利用dictionary的特性. 當我抓到第一組資料時, ex: module1: name0, type0, comt0 name1, type1, comt1 name2, type2, comt2 .... nameN, typeN, comtN module2: name0, type0, comt0 name1, type1, comt1 .... nameM, typeM, comtM ....... moduleK: name0, type0, comt0 name1, type1, comt1 .... nameL, typeL, comtL 由於幾個module是不一定, 每個module裡有幾組name/type/comt也不一定. 我想要做成一個方便資料搜索的dictionary 當我想搜尋module2時, 會去找module2裡的dictionary, 然後去找nameX, 然後資料會找到nameX, typeX, comtX 我現在碰到的問題是: 由於不同模組下的name, 有可能會相同, 但type和comt可能會不同, 且我不知道會有幾個module, 所以我要怎麼動態去產生 不同module下的dictionary. 請教各位前輩高手了. 謝謝 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 210.61.209.67 ※ 文章網址: https://www.ptt.cc/bbs/C_Sharp/M.1459408609.A.815.html

03/31 20:18, , 1F
做一個class放module, name, type, comt
03/31 20:18, 1F

03/31 20:18, , 2F
key用module和name
03/31 20:18, 2F

03/31 20:20, , 3F
(複寫該class的Equals和GetHashCode)
03/31 20:20, 3F

03/31 20:26, , 4F
其實你這兩層的Dictionary也沒什麼問題,哪裡不明白呢?
03/31 20:26, 4F

04/06 14:52, , 5F
是name會重覆的問題吧?dictionary不能有相同的key
04/06 14:52, 5F

04/06 14:53, , 6F
不想生新class 就改成IEnumerable<KeyValuePair<>>
04/06 14:53, 6F
文章代碼(AID): #1M_CxXWL (C_Sharp)