Question Details

No question body available.

Tags

c# overlap

Answers (5)

May 22, 2026 Score: 1 Rep: 1,150 Quality: Low Completeness: 30%

Can't you just start j with int j = i + 1 in inner loop? Then you also wouldn't need if (i != j).

May 22, 2026 Score: 0 Rep: 60 Quality: Low Completeness: 0%

In the case of i>j, buttons[j] and buttons[i] have already been compared. And if there is hasOverlap, there is no need to compare further.

May 22, 2026 Score: 0 Rep: 2,819 Quality: Low Completeness: 30%

Make sure all buttons are already added before you run your loop, then just start the inner loop at j=i+1.

May 22, 2026 Score: 0 Rep: 369 Quality: Low Completeness: 10%

When you compare, first remove a button from the List, and compare it to the others. Repeat until all the buttons are removed (or otherwise done). So, a "while" loop. You can also use "Rect.Intersect()" as another way for checking overlap.

May 22, 2026 Score: 0 Rep: 77,282 Quality: Low Completeness: 10%

also, since you want to know "if any buttons overlap" you can stop the comparisons on the first overlap found. You do this with a break or a return if this is neatly in its own function.