HomeCSharpC# Error CS1959 – ‘{0}’ is of type ‘{1}’. The type specified in a constant declaration must be sbyte, byte, short, ushort, int, uint, long, ulong, char, float, double, decimal, bool, string, an enum-type, or a reference-type.

C# Error CS1959 – ‘{0}’ is of type ‘{1}’. The type specified in a constant declaration must be sbyte, byte, short, ushort, int, uint, long, ulong, char, float, double, decimal, bool, string, an enum-type, or a reference-type.

C# Error

CS1959 – ‘{0}’ is of type ‘{1}’. The type specified in a constant declaration must be sbyte, byte, short, ushort, int, uint, long, ulong, char, float, double, decimal, bool, string, an enum-type, or a reference-type.

Reason for the Error & Solution

‘name’ is of type ‘type’. The type specified in a constant declaration must be sbyte, byte, short, ushort, int, uint, long, ulong, char, float, double, decimal, bool, string, an enum-type, or a reference-type.

The types permitted in a const declaration are limited to those described in this message.

To correct this error

  1. Declare the constant with an allowed type.

Example

The following code produces CS1959 because null is not a type.

// cs1959.cs  
class Program  
    {  
        static void Test<T>() where T : class  
        {  
            const T x = null; // CS1959  
        }  
    }  

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

This C# program calculates and displays an upper triangular matrix based on user input. Problem Statement: The program takes the...
This C# program serves as a demonstration of bitwise operators, which are fundamental operators used for manipulating individual bits in...
This C# program is designed to interchange or swap the columns of a matrix. A matrix is a two-dimensional array...