C# Error CS0572 – ‘{0}’: cannot reference a type through an expression; try ‘{1}’ instead

C# Error

CS0572 – ‘{0}’: cannot reference a type through an expression; try ‘{1}’ instead

Reason for the Error & Solution

‘type’ : cannot reference a type through an expression; try ‘path_to_type’ instead

An attempt was made to access a member of a class through an identifier, which is not permitted in this situation.

The following sample generates CS0572:

// CS0572.cs  
using System;  
class C  
{  
   public class Inner  
   {  
      public static int v = 9;  
   }  
}  
  
class D : C  
{  
   public static void Main()  
   {  
      C cValue = new C();  
      Console.WriteLine(cValue.Inner.v);   // CS0572  
      // try the following line instead  
      // Console.WriteLine(C.Inner.v);  
   }  
}  

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