HomeCSharpC# Error CS1001 – Identifier expected

C# Error CS1001 – Identifier expected

C# Error

CS1001 – Identifier expected

Reason for the Error & Solution

Identifier expected

You did not supply an identifier. An identifier is the name of a class, struct, namespace, method, variable, and so on, that you provide.

The following example declares a simple class but does not give the class a name:

public class //CS1001
{
    public int Num { get; set; }
    void MethodA() {}
}

The following sample generates CS1001 because, when declaring an enum, you must specify members:

public class Program
{
    enum Colors
    {
        'a', 'b' // CS1001, 'a' is not a valid int identifier
        // The following line shows examples of valid identifiers:
        // Blue, Red, Orange
    };

    public static void Main()
    {
    }
}

Parameter names are required even if the compiler doesn’t use them, for example, in an interface definition. These parameters are required so that programmers who are consuming the interface know something about what the parameters mean.

interface IMyTest
{
    void TestFunc1(int, int);  // CS1001
    // Use the following line instead:
    // void TestFunc1(int a, int b);
}

class CMyTest : IMyTest
{
    void IMyTest.TestFunc1(int a, int b)
    {
    }
}

Leave a Reply

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...