Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个IEnumerable<int>可以打印出来并且可以加倍的(下面的代码)。这不是问题。如何调整 linq 语句,使其采用这 3 个值并输出 6 个值?例如,将值设置为 double 和 half,因此值将是12, 3, 16, 4, 8, 2。
IEnumerable<int>
12, 3, 16, 4, 8, 2
foreach (var v in (new int[] { 6, 8, 4 }).Select(s=>s*2)) Console.WriteLine(v);
你需要SelectMany:
SelectMany
foreach (var v in (new[] { 6, 8, 4 }).SelectMany(s => new[] { s * 2, s / 2 })) Console.WriteLine(v);