C# Error CS1519 – Invalid token ‘{0}’ in class, record, struct, or interface member declaration

C# Error

CS1519 – Invalid token ‘{0}’ in class, record, struct, or interface member declaration

Reason for the Error & Solution

Invalid token ‘token’ in class, struct, or interface member declaration

This error is generated whenever a token is encountered in a location where it does not belong. A token is a keyword; an identifier (the name of a class, struct, method, and so on); a string, character, or numeric literal value such as 108, "Hello", or ‘A’; or an operator or punctuator such as == or ;.

Any , struct, or interface member declaration that contains invalid modifiers before the type will generate this error. To fix the error, remove the invalid modifiers.

The following sample generates CS1519 in five places because tokens are placed in locations where they are not valid:

// CS1519.cs  
// Generates CS1519 because a class name cannot be a number:  
class Test 42
{  
// Generates CS1519 because of 'j' following 'I'  
// with no comma between them:  
    int i j;
// Generates CS1519 because of "checked" on void method:  
    checked void f4();
  
// Generates CS1519 because of "num":  
    void f5(int a num){}
  
// Generates CS1519 because of namespace inside class:  
    namespace;
  
}  

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