Compiler Error CS0542

'user-defined type' : member names cannot be the same as their enclosing type

The members of a class or struct cannot have the same name as the class or struct, unless the member is a constructor.

The following sample generates CS0542:

// CS0542.cs  
class C  
{  
    public int C;  
}  

This error might be caused if you inadvertently put a return type on a constructor, which in effect makes it into an ordinary method. The following example generates CS0542 because F is a method, not a constructor, because it has a return type:

// CS0542.cs  
class F  
{  
   // Remove void from F() to resolve the problem.  
   void F()   // CS0542, same name as the class  
   {  
   }  
}  
  
class MyClass  
{  
   public static void Main()  
   {  
   }  
}