Let's say I have a collection of elements which have a float
property.
I was grouping by it but I found I was getting undesired groupings.
For example (with a double
to take profit of Random
's NextDouble()
):
void Main()
{
var examples = new List<Example>();
var rnd = new Random();
for (int i = 0; i < 100; i++)
{
var newPosition = rnd.NextDouble();
examples.Add(new Example { Position = newPosition });
}
examples.GroupBy(x => x.Position).Dump();
}
class Example
{
public double Position { get; set; }
}
This would lead into something like this:
Grouping 0,00075609376689237252
Grouping 0,0010980092925475954
Grouping 0,0020200186418462629
Grouping 0,0062832017458431429
...
Question is (worthy or not): how could I group them by allowing to have a "boundary" like... +- 0.05?