The Rectangle struct is well implemented IMHO.
Just a few remarks:
- It is not necessary to implement the == operator again, just use the
Equalsmethod. - Calculate
RightanBottomonce in the constructor to avoid multiple calculations. - I would expect, that
RightandBottomare inside the Rectangle. - Use properties instead of public fields for
X,Y,WidthandHeight
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.