Compiler Warning (level 2) CS0108

“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
      // Use the following line instead:
      // public static new int i = 2;

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

请参阅

new 修饰符(C# 参考)

new