Napomena
Pristup ovoj stranici zahteva autorizaciju. Možete pokušati da se prijavite ili da promenite direktorijume.
Pristup ovoj stranici zahteva autorizaciju. Možete pokušati da promenite direktorijume.
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();
//...
}
Povratne informacije za .NET
.NET je projekat otvorenog koda. Izaberite vezu da biste pružili povratne informacije: