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

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

You May Also Like

C# Compiler Error CS0442 – ‘Property’: abstract properties cannot have private accessors Reason for the Error You’ll get this error...
This is a really simple one . Below is a simple example of an enum called “Designation” defined with the...
This blog post explain the usage of the Checked Block in .NET and how you can use them in Visual...