컴파일러 오류 CS0542

업데이트: 2007년 11월

오류 메시지

'user-defined type': 멤버 이름은 바깥쪽 형식과 같을 수 없습니다.
'user-defined type' : member names cannot be the same as their enclosing type

동일한 구문에서 같은 이름을 여러 번 사용했습니다. 이 오류는 생성자에 실수로 반환 형식을 넣었을 때 발생합니다.

다음 샘플에서는 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()
   {
   }
}

클래스의 이름이 'Item'이고 인덱서가 this로 선언되어 있으면 이 오류가 발생할 수 있습니다. 생생된 코드에서 기본 인덱서의 이름은 'Item'으로 지정되므로 충돌이 발생합니다.

// CS0542b.cs
class Item
{
   public int this[int i]  // CS0542
   {
      get
      {
         return 0;
      }
   }
}

class CMain
{
   public static void Main()
   {
   }
}