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

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

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