更新: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);
      }
   }
}