Compiler Error CS0283

The type 'type' cannot be declared const

The type specified in a constant declaration must be byte, char, short, int, long, 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 can be converted to the target type by implicit conversion.

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;
    }
}