假设我有
class objectA
{
string name;
}
class objectB
{
List<objectA> la = new List<objectA>();
}
main()
{
List<objectB> lb = new List<objectB>();
/*some operations that results in lb having many objectB objects
and each objectB having many objectA.
lb
objectB1
objectA1
somestring1
objectA2
somestring2
objectA3
somestring3
.
.
objectA166
somestring4
objectB2
objectA167
somestring5
objectA168
somestring6
objectA169
somestring7
.
.
objectA176
somestring8
.
.
.
objectB5
objectA267
somestring9
objectA268
somestring10
objectA269
somestring11
.
.
objectA276
somestring12
*/
}
什么是linq查询才能获得所有的字符串?
理想情况下,我可以做一些像
这样的事情var w = from f in lb select lb.(each objectB).(each objectA).name
我目前的解决方法是枚举集合并将每个名称添加到列表中,但我认为必须有LINQ方法来执行此操作。
答案 0 :(得分:1)
你可以这样做:
var w = from b in lb
from a in b.la
select a.name;