« MoreLINQ » : différence entre les versions
De Banane Atomic
Aller à la navigationAller à la recherche
Ligne 44 : | Ligne 44 : | ||
var items = new[] | var items = new[] | ||
{ | { | ||
new | new { Id = 1, Name = "One" }, | ||
new | new { Id = 2, Name = "Two" }, | ||
new | new { Id = 3, Name = "One" }, | ||
new | new { Id = 2, Name = "Two again" } | ||
}; | }; | ||
Version du 14 novembre 2020 à 22:51
Links
Add
dotnet add package MoreLINQ |
Operators
Aggregate
Batch
Batches the source sequence into sized buckets.
Enumerable .Range(1, 10) .Batch(3); // split the sequence into sequences of max length 3 // [1, 2, 3] // [4, 5, 6] // [7, 8, 9] // [10] |
Cartesian
Returns the Cartesian product of two or more sequences by combining each element from the sequences and applying a user-defined projection to the set.
Enumerable .Range(1, 2) .Cartesian( Enumerable.Range(10, 2), (x, y) => $"{x} - {y}"); // 1 - 10 // 1 - 11 // 2 - 10 // 2 - 11 |
DistinctBy
Returns all distinct elements of the given source, where "distinctness" is determined via a projection and the default equality comparer for the projected type.
var items = new[] { new { Id = 1, Name = "One" }, new { Id = 2, Name = "Two" }, new { Id = 3, Name = "One" }, new { Id = 2, Name = "Two again" } }; items.DistinctBy(x => x.Id); // 1 2 3 items.DistinctBy(x => x.Name); // 1 2 2 |