Unsurprisingly, given your implementation of GetHashCode , which always returns the same value. Distinct relies on a good hash function to work efficiently.
When implementing class interfaces, you need to read the documentation first , otherwise you do not know what contract you intend to implement. one
In your code, the solution should forward GetHashCode to Class_reglement.Numf.GetHashCode and implement it accordingly.
In addition, your Equals method is filled with unnecessary code. It could be rewritten as follows (the same semantics, 1/4 of the code, more readable):
public bool Equals(Class_reglement x, Class_reglement y) { return x.Numf == y.Numf; }
In addition, the ToList call ToList not needed and takes a lot of time: AddRange accepts any IEnumerable , so conversion to List not required. AsEnumerable also redundant here, since processing the result in AddRange will still result in this.
1 The implementation of the code, not knowing what it actually does, is called cult programming of the load . This is a surprisingly common practice. This basically does not work.
Konrad Rudolph Jul 14 2018-11-11T00: 00Z
source share