Notiz
Zougrëff op dës Säit erfuerdert Autorisatioun. Dir kënnt probéieren, Iech unzemellen oder Verzeechnesser ze änneren.
Zougrëff op dës Säit erfuerdert Autorisatioun. Dir kënnt probéieren, Verzeechnesser ze änneren.
The type 'type' cannot be declared const
The type specified in a constant declaration must be byte
, sbyte
, ushort
, short
, uint
, int
, ulong
, long
, char
, float
, double
, decimal
, bool
, string
, an enum type, or a reference type that is assigned a value of null
. Each constant expression must yield a value of the target type or of a type that is implicitly convertible to the target type.
Example
The following example generates CS0283.
// CS0283.cs
struct MyTest
{
}
class MyClass
{
// To resolve the error but retain the "const-ness",
// change const to readonly.
const MyTest test = new MyTest(); // CS0283
public static int Main() {
return 1;
}
}