[問題] class 中的field轉string array

看板C_Sharp (C#)作者 (彈彈的哀傷)時間10年前 (2015/04/08 20:26), 編輯推噓1(101)
留言2則, 2人參與, 最新討論串1/2 (看更多)
請問一下 我現在有個class如下 class Test { public string AAA{get;set;} public string BBB{get;set;} } 再來有個test的list List<Test> test; 最後是有個string list List<List<string>> output; 我要把AAA的內容放到output[0] BBB放到output[1]; 我現在只想到 output[0] = test.Select(x=>x.AAA).ToList<string>(); output[1] = test.Select(x=>x.BBB).ToList<string>(); 如果我這個class中的field有 十個我就要寫十行 覺得有點麻煩耶! 有沒有什麼寫法可以再縮減的啊? 謝謝大家! -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 114.32.241.230 ※ 文章網址: https://www.ptt.cc/bbs/C_Sharp/M.1428495998.A.6F1.html

04/08 20:38, , 1F
Reflection
04/08 20:38, 1F

04/08 21:23, , 2F
搞不定,大大有範例嗎?linq的select中用reflection的?謝
04/08 21:23, 2F
文章代碼(AID): #1L9Hv-Rn (C_Sharp)
討論串 (同標題文章)
文章代碼(AID): #1L9Hv-Rn (C_Sharp)