Click to Rate and Give Feedback
MSDN
MSDN Library
Visual Studio 2005
Visual Studio
Visual C#
C# Reference
C# Compiler Options
C# Compiler Errors
 Compiler Error CS0542

  Switch on low bandwidth view
This page is specific to
Microsoft Visual Studio 2005/.NET Framework 2.0

Other versions are also available for the following:
Visual C# Reference: Errors and Warnings 
Compiler Error CS0542 

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()
   {
   }
}
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker