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

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

メンバーは、基底クラスのメンバーと同じ名前で宣言されました。 しかし、new 修飾子は使用されませんでした。

次の例では CS0108 が生成されます。 以下の 2 つの方法のいずれかで CS0108 を解決できます。

  • メンバーの隠蔽が意図したものではなかった場合、派生クラスのメンバーの名前を変更します。

  • new 修飾子を使用して、派生メンバーによる基底メンバーの隠蔽が意図したものであったことを宣言します。

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

namespace MyNamespace;

public class BaseClass
{
    public int i = 1;
}

public class DerivedClass : BaseClass
{
    public static int i = 2;   // CS0108
    // Use the following line instead:
    // public static new int i = 2;

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

関連項目