Compiler Warning (level 2) CS0108
'member1' hides inherited member 'member2'. Use the new keyword if hiding was intended.
A variable was declared with the same name as a variable in a base class. However, the new keyword was not used. This warning informs you that you should use new; the variable is declared as if new had been used in the declaration.
The following sample generates 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);
}
}
}
See also
Collaborate with us on GitHub
The source for this content can be found on GitHub, where you can also create and review issues and pull requests. For more information, see our contributor guide.
.NET feedback
The .NET documentation is open source. Provide feedback here.
Feedback
Submit and view feedback for