C# Error CS0708 – ‘{0}’: cannot declare instance members in a static class

C# Error

CS0708 – ‘{0}’: cannot declare instance members in a static class

Reason for the Error & Solution

‘field’: cannot declare instance members in a static class

This error occurs if you declare a non-static member in a class that is declared static. It is not possible to create instances of static classes, so instance variables would not be meaningful. The static keyword should be applied to all members of static classes.

The following sample generates CS0708:

// CS0708.cs  
// compile with: /target:library  
public static class C  
{  
   int i;  // CS0708  
   static int j;  // OK  
}  

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