kasperhj
kasperhj

Reputation: 10482

Convert IEnumerable<IGrouping<,>> to array

Is there an easy way of converting remaining in the following code to a 1-D array.

var groups = data.OrderBy(d => d.Time).GroupBy(d => d.Period);
var first = groups.First().ToArray();
var remaining = groups.Skip(1).??

Upvotes: 3

Views: 2166

Answers (2)

D Stanley
D Stanley

Reputation: 152556

Use SelectMany to "flatten" a collection of collections:

var remaining = groups.Skip(1).SelectMany(d => d).ToArray();

Upvotes: 2

King King
King King

Reputation: 63317

var remaining = groups.Skip(1).SelectMany(g=>g).ToArray();

Upvotes: 6

Related Questions