Compiler Error CS0283
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.
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;
}
}
.NET feedback
.NET is an open source project. Select a link to provide feedback: