沒有輸入和輸出就很難解釋這一點。我做了一個簡單的汽車示例以避免不必要的項目細節。SelectMany的相反之處是什麼?
我有這樣的名單:
List<car> cars = new List<car>()
{
new car() { carname = "bmw", carwheels = new List<int>() { 1, 2, 3, 4 } },
new car() { carname = "cadillac", carwheels = new List<int>() { 1, 2, 3, 4 } },
new car() { carname = "mustang", carwheels = new List<int>() { 1, 2, 3, 4 } }
};
我想這個輸出,擴展類:
{
{ carname = "bmw", carwheel = 1 },
{ carname = "bmw", carwheel = 2 },
{ carname = "bmw", carwheel = 3 },
{ carname = "bmw", carwheel = 4 },
{ carname = "cadillac", carwheel = 1 },
{ carname = "cadillac", carwheel = 2 },
{ carname = "cadillac", carwheel = 3 },
{ carname = "cadillac", carwheel = 4 },
{ carname = "mustang", carwheel = 1 },
{ carname = "mustang", carwheel = 2 },
{ carname = "mustang", carwheel = 3 },
{ carname = "mustang", carwheel = 4 }
}
有沒有辦法通過IEnumerable的擴展方法的投影來做到這一點?與SelectMany()相反的東西。
爲什麼相反,是不是'SelectMany'確實是什麼? –
@TimSchmelter - 根據我的理解,'SelectMany()'會將最下面的列表展平,並將它們拼成單打,每個列表都有一個車輪列表。是否有另一個重載SelectMany()我應該學習? – BeemerGuy
這不是'SelectMany'的反義詞,這*是*'SelectMany'。 – dasblinkenlight