I could break my problem into something less trivial:
var d = Enumerable.Range(1, 100); var f = d.Select(t => new Person());
Now, essentially, I am doing this:
f = f.Concat(f);
Please note that the request has not been completed so far. At runtime, f is still d.Select(t => new Person()) not executed . Thus, the last statement at runtime can be broken down into:
f = f.Concat(f); //which is f = d.Select(t => new Person()).Concat(d.Select(t => new Person()));
which is obvious for creating 100 + 100 = 200 new instances of people. So,
f.Distinct().ToList(); //yields 200, not 100
what is the right behavior.
Edit: I could rewrite the extension method as simple as
public static IEnumerable<T> Repeat<T>(this IEnumerable<T> source, int times) { source = source.ToArray(); return Enumerable.Range(0, times).SelectMany(_ => source); }
I used the dasblinkenlight suggestion to fix this problem.
nawfal
source share