看板 C_Sharp 關於我們 聯絡資訊
各位前輩好 小弟正在新增一筆二維List陣列資料 資料內容是從string陣列裡面抓值, 去分割資料存入 listArticle 為字串陣列 DlistArticel 為二維List陣列 listArticle 內容為abc|cda, xyz|zyx..... for (int i = 0; i < listArticle.Count; i++ ) { string[] sArray1 = listArticle[i].Split(new char[1]{'|'}) ; foreach (string DA in sArray1) { DlistArticle.Add(new List<string>() { Convert.ToString(i) ,DA }); } } 小弟我想將資料存為 DlistArticel[0][0] abc DlistArticel[0][1] cba DlistArticel[1][0] xyz DlistArticel[1][1] zyx 但寫法卻是存為 DlistArticel[0][0] abc DlistArticel[1][0] cba DlistArticel[2][0] xyz DlistArticel[3][0] zyx 小弟對二維List陣列不太熟 自己摸索找資料後大概知道儲存方法是 存第一次 就會固定[0][], 第二次就會[1][] DlistArticle.Add(new List<string>() { XXX }); 想請問各位前輩有甚麼方法可以儲存成小弟希望的那樣 我已經摸索找尋很久了, 還是沒辦法修改成功 祈求各位幫忙了!! 先在此感謝!! ------------------------------------------------ 我有一組string陣列是儲存使用者選擇的物品, 中間加入|符號後累加上去 例如 陣列i 有兩筆字串 i[0] a|b|c, i[1] x|y|z 我現在需要把他們分解好放在 listboxA 上 當我選擇 listboxB 第一個選項時 listboxA 的選項會跑出 i[0] 裡面分解好的字串 選擇 listboxB 第二個選項時會跑 i[1] 分解好的字串 例如 listboxA 當listboxB為 選項一 | 選項二 a | x b | y c | z -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 114.39.215.177 ※ 文章網址: https://www.ptt.cc/bbs/C_Sharp/M.1431484531.A.F96.html ※ 編輯: wmohmoo (114.39.215.177), 05/13/2015 10:37:03
GoalBased: 你還是先學習一下if和for到底是怎樣運作的吧@@.. 05/13 12:25
GoalBased: 你這個寫法當然會是下面那種,還有先看一下list介紹 05/13 12:25
wmohmoo: G大 我知道我那方法會跑成那樣 但我想不出來怎麼跑成我要 05/13 13:26
wmohmoo: 的 小弟對List的新增方式還有待加強....不太熟 05/13 13:27
GoalBased: 你的DlistArticel宣告是怎樣? 05/13 13:51
J002: DlistArticle要不要改成List<Dictionary<int, string>> ? 05/13 14:18
wmohmoo: G大 List<List<string>> DlistArticle = 05/13 14:33
wmohmoo: new List<List<string>>(); 05/13 14:33
wmohmoo: G大 麻煩了 感謝! J大 我來找找試試你說的方法 感謝! 05/13 14:35
GoalBased: 或者說說原始的問題是怎麼樣吧,如果方向錯了,作法對 05/13 14:43
GoalBased: 了也是徒勞無功 05/13 14:43
※ 編輯: wmohmoo (218.166.47.120), 05/13/2015 14:58:31 ※ 編輯: wmohmoo (218.166.47.120), 05/13/2015 14:58:57 ※ 編輯: wmohmoo (218.166.47.120), 05/13/2015 14:59:51
wmohmoo: G大 不知道我方向有無走偏 目前主要就卡在這...... 05/13 15:00
wmohmoo: J大 我用了你說的方式存成[0]{"ABC","CBA",...} [1].... 05/14 09:50
wmohmoo: 但我不清楚怎麼叫出來放入listbox中 完全沒接觸過這個... 05/14 09:51
wmohmoo: 感謝兩位 最後我用J002大的方向寫出來了!! 感謝 05/14 16:31
J002: 恭喜! 05/16 01:20