C# Error CS1023 – Embedded statement cannot be a declaration or labeled statement

C# Error

CS1023 – Embedded statement cannot be a declaration or labeled statement

Reason for the Error & Solution

Embedded statement cannot be a declaration or labeled statement

An embedded statement, such as the statements following an if statement, can contain neither declarations nor labeled statements.

The following sample generates CS1023 twice:

// CS1023.cs  
public class a  
{  
   public static void Main()  
   {  
      if (1)  
         int i;      // CS1023, declaration is not valid here  
  
      if (1)  
         xx : i++;   // CS1023, labeled statement is not valid here  
   }  
}  

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