日期:2014-05-18 浏览次数:21042 次
public class Album {
public List<Photo> Photos { get; set; }
}
public class Photo {
public string Name { get; set; }
}
List<Album> albums = new List<Album>();
albums.Add(new Album {
Photos = new List<Photo> {
new Photo{Name ="Photo1"},
new Photo{Name ="Photo2"}
}});
albums.Add(new Album {
Photos = new List<Photo> {
new Photo{Name ="Photo3"},
new Photo{Name ="Photo4"},
new Photo{Name ="Photo5"}
}
});
var sample = new List<List<string>>();
sample.Add(new List<string> { "a", "b" });
sample.Add(new List<string> { "c", "d", "e" });
List<Photo> list = new List<Photo>();
var vs = from p in albums.Select(x => x.Photos) select p;
foreach (var v in vs)
{
list.AddRange((from p in v select p).ToArray());
}
------解决方案--------------------
一个selectMany操作而已
------解决方案--------------------
linq处理这些很给力啊
SelectMany(x=>x),x后面还可以做很多事,例如只取第一个数据等等
------解决方案--------------------