I have a method where I’d like to use a Rectangle optional parameter with default value of (1,1,1,1).
void Method(int i, int j = 1, Rectangle rect = new Rectangle(1,1,1,1)) {} //error
How do I resolve this? (I’m using XNA, so it’s a Microsoft.Xna.Framework.Rectangle.)
You don’t. optional parameters must be compile time constants, and
new Rectangle(1,1,1,1)isn’t a compile time constant.You could have two method overloads, one that doesn’t have a rectangle: