Compiler Warning (level 2) CS0108
'member1' hides inherited member 'member2'. Use the new keyword if hiding was intended.
A member was declared with the same name as a member in a base class. However, the new modifier was not used.
The following sample generates CS0108. You can resolve CS0108 in one of two ways:
Rename the member in the derived class if member hiding was not intended.
Use the
new
modifier to declare that the derived member hiding of the base member was intentional.
// 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);
}
}
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.
Feedback
https://aka.ms/ContentUserFeedback.
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:Submit and view feedback for