作者gundan (弹弹的哀伤)
看板C_Sharp
标题[问题] class 中的field转string array
时间Wed Apr 8 20:26:36 2015
请问一下
我现在有个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://webptt.com/cn.aspx?n=bbs/C_Sharp/M.1428495998.A.6F1.html
1F:推 YahooTaiwan: Reflection 04/08 20:38
2F:→ gundan: 搞不定,大大有范例吗?linq的select中用reflection的?谢 04/08 21:23