Compiler Error CS1736
Default parameter value for must be a compile-time constant
The following sample generates CS1736:
// CS1736.cs
public unsafe class C
{
static void F(int i = G())
{
// ...
}
static int G() => 0;
A default parameter value is evaluated upon the invocation of the method. What a value may be when the method is eventually invoked cannot be pre-determined at declaration-time unless that value is constant at compile-time.
If a dynamically evaluated value is required, consider using a compile-time constant as a marker value which is then checked at run-time:
static void F(int i = -1)
{
if(i == -1) i = G();
//...
}
.NET feedback
.NET is an open source project. Select a link to provide feedback: