I have the following linked list:
LinkedList<Segment> myList = new LinkedList<Segment>();
Why when I do:
myList.Remove(new Segment(4,8));
the following Segment.Equals() method is called:
class Segment
{
...
public override bool Equals(object obj)
{
return Equals((Segment)obj);
}
}
instead of this one:
class Segment
{
...
public bool Equals(Segment other)
{
return other.V1 == V1 && other.V2 == V2;
}
}
Isn’t there any way to skip object boxing and unboxing and use the latter – more fast – approach?
Thanks.
You need your element type to implement the
IEquatable<T>interface: