StackOverflow when setting ListView.ItemsSource

So, I have a simple structure Pointwith two doubles Xand Y. I calculated an array of about three hundred of them and set this array as ItemsSource for ListView in WPF. This call eventually calls a StackOverflowException.

The debugger is debugged at the beginning of the method Equalsin my structure, which I implemented like this (if this is important):

public override bool Equals(object obj)
{
  if (obj is Point)
    return Equals(obj);

  return false;
}
public bool Equals(Point other)  // Implement IEquatable<T>
{
  return this.x == other.x && this.y == other.y;
}

If I changed this to the following:

public override bool Equals(object obj)
{
  return false;
}

Nothing happens and the numbers are displayed. I really don’t know what I did wrong, so I don’t know how to fix it. Any pointers?

+3
source share
2 answers

Equals(object obj) , obj object, a Point. , , .

obj Point, , Equals(Point other):

public override bool Equals(object obj)
{
  if (obj is Point)
    return Equals((Point) obj);

  return false;
}
+6

quickie - Equals (object):

public override bool Equals(object obj)
{
    return (obj is Point) && Equals((Point)obj);
}

( , , .)

+5

Source: https://habr.com/ru/post/1778469/


All Articles