Error Message
'user-defined type' : member names cannot be the same as their enclosing type
A name was used more than once in the same construct. This error might be caused by inadvertently putting a return type on a constructor.
The following sample generates CS0542:
// 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()
{
}
} If your class is named 'Item' and has an indexer declared as this, you may get this error. A default indexer is given the name 'Item' in the emitted code, creating the conflict.
// CS0542b.cs
class Item
{
public int this[int i] // CS0542
{
get
{
return 0;
}
}
}
class CMain
{
public static void Main()
{
}
}