Sure - you can do it in a single call to SelectMany
with an embedded call to Skip
:
var query = slotIds.SelectMany((value, index) => slotIds.Skip(index + 1),
(first, second) => new { first, second });
Here's an alternative option, which doesn't use quite such an esoteric overload of SelectMany
:
var query = from pair in slotIds.Select((value, index) => new { value, index })
from second in slotIds.Skip(pair.index + 1)
select new { first = pair.value, second };
These do basically the same thing, just in slightly different ways.
Here's another option which is much closer to your original:
var query = from index in Enumerable.Range(0, slotIds.Count)
let first = slotIds[index] // Or use ElementAt
from second in slotIds.Skip(index + 1)
select new { first, second };
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…