컴파일러 경고(수준 2) CS0108

업데이트: 2007년 11월

오류 메시지

'member1'은(는) 상속된 'member2' 멤버를 숨깁니다. 숨기려면 new 키워드를 사용하십시오.
'member1' hides inherited member 'member2'. Use the new keyword if hiding was intended.

기본 클래스의 변수와 동일한 이름의 변수를 선언했지만 new 키워드를 사용하지 않았습니다. 이경고는사용자가new를 사용해야 함을 알립니다. 변수는 new가 선언에 사용된 것처럼 선언됩니다.

다음 샘플에서는 CS0108 오류가 발생하는 경우를 보여 줍니다.

// CS0108.cs
// compile with: /W:2
using System;

namespace x
{
   public class clx
   {
      public int i = 1;
   }

   public class cly : clx
   {
      public static int i = 2;   // CS0108, use the new keyword
      // the compiler parses the previous line as if you had specified:
      // public static new int i = 2;

      public static void Main()
      {
         Console.WriteLine(i);
      }
   }
}