コンパイラの警告 (レベル 2) CS0108

更新 : 2007 年 11 月

エラー メッセージ

'member1' は継承メンバ 'member2' を隠します。非侮ヲにする場合は、new キーワードを使用してください。

変数が、基本クラスの変数と同じ名前で宣言されました。しかし、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);
      }
   }
}