Optional parameter in method not compile-time constant error with Rectangle

c#, compiler-errors, optional-parameters

Solution

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:

void Method(int i, int j = 1) 
{
    Method(i, j, new Rectangle(1,1,1,1)) 
}

Problem

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`.)

Original source