班级定义:
Dictionary<int, HubObject> result
我的Key Value
0 {Hub={"Hub0", 600}, Sites={{"Chicago", 100}, {"Minneapolis", 200}, {"Newyork", 300}}}
1 {Hub={"Hub1", 300}, Sites={{"Portland", 100}, {"Santaclara", 200}}}
包含..
List<List<string>>
希望以下面的格式将其转换为"SiteId", "Value"
"Hub0", 600
"Chicago", 100
"Minneapolis", 200
"Newyork", 300
"Hub1", 300
"Portland", 100
"Santaclara", 200
。
var sitesList = result.SelectMany(r => r.Value.Sites.Select(x => new
{
x.SiteId,
x.Value
})).ToList();
这是我迄今取得的成就
"SiteId", "Value"
"Chicago", 100
"Minneapolis", 200
"Newyork", 300
"Portland", 100
"Santaclara", 200
这给了我......
Hub0
如何为此添加“Hub”行?比如,第一个WebElement element = driver.findElement(By.id("id-home_prevButton");
((JavascriptExecutor)driver).executeScript("arguments[0].click();", element);
父项后面跟着它所属的所有网站,依此类推。
答案 0 :(得分:2)
我认为你可以这样做:
var sitesList=result.SelectMany(r =>
{
return r.Value.Sites
.Concat(new List<Site>{r.Value.Hub})
.Select (s =>new{s.SiteId,s.Value});
});
你甚至可以这样做:
var sitesList=result.SelectMany(r =>
new List<Site>{r.Value.Hub}.Concat(r.Value.Sites)
.Select (s =>new{s.SiteId,s.Value}));