Skip to main content
added 532 characters in body
Source Link
JanDotNet
  • 8.6k
  • 2
  • 22
  • 48

The Rectangle struct is well implemented IMHO.

Just a few remarks:

  • It is not necessary to implement the == operator again, just use the Equals method.
  • Calculate Right an Bottom once in the constructor to avoid multiple calculations.
  • I would expect, that Right and Bottom are inside the Rectangle.
  • Use properties instead of public fields for X, Y, Width and Height

If I don't allow negative Widths nor Heights, should their types be uint? I'm using int because most of the "size" variables in .net are int (instead of uint). Ie: System.Collections.Generic.List's Count it a int, even tho it can never be negative.

I wouldn't use uint - throwing an ArgumentOutOfRangeException is absolutely OK here

Is it a bad design for my rectangle to implement IEnumerable? Is it counter intuitive?

In my eyes - yes. It is not clear what to get when iterating over an rectangle.

The Rectangle struct is well implemented IMHO.

Just a few remarks:

  • It is not necessary to implement the == operator again, just use the Equals method.
  • Calculate Right an Bottom once in the constructor to avoid multiple calculations.
  • I would expect, that Right and Bottom are inside the Rectangle.
  • Use properties instead of public fields for X, Y, Width and Height

The Rectangle struct is well implemented IMHO.

Just a few remarks:

  • It is not necessary to implement the == operator again, just use the Equals method.
  • Calculate Right an Bottom once in the constructor to avoid multiple calculations.
  • I would expect, that Right and Bottom are inside the Rectangle.
  • Use properties instead of public fields for X, Y, Width and Height

If I don't allow negative Widths nor Heights, should their types be uint? I'm using int because most of the "size" variables in .net are int (instead of uint). Ie: System.Collections.Generic.List's Count it a int, even tho it can never be negative.

I wouldn't use uint - throwing an ArgumentOutOfRangeException is absolutely OK here

Is it a bad design for my rectangle to implement IEnumerable? Is it counter intuitive?

In my eyes - yes. It is not clear what to get when iterating over an rectangle.

Source Link
JanDotNet
  • 8.6k
  • 2
  • 22
  • 48

The Rectangle struct is well implemented IMHO.

Just a few remarks:

  • It is not necessary to implement the == operator again, just use the Equals method.
  • Calculate Right an Bottom once in the constructor to avoid multiple calculations.
  • I would expect, that Right and Bottom are inside the Rectangle.
  • Use properties instead of public fields for X, Y, Width and Height