diff --git a/docs/csharp/misc/cs0060.md b/docs/csharp/misc/cs0060.md index b3c8f4193aef1..437e82f250c18 100644 --- a/docs/csharp/misc/cs0060.md +++ b/docs/csharp/misc/cs0060.md @@ -2,36 +2,40 @@ description: "Compiler Error CS0060" title: "Compiler Error CS0060" ms.date: 07/20/2015 -f1_keywords: +f1_keywords: - "CS0060" -helpviewer_keywords: +helpviewer_keywords: - "CS0060" ms.assetid: ae6d4fb7-5ff9-4883-82c3-f55b190f439a --- # Compiler Error CS0060 -Inconsistent accessibility: base class 'class1' is less accessible than class 'class2' - - Class accessibility should be consistent between the base class and inherited class. - - The following sample generates CS0060: - -```csharp -// CS0060.cs -class MyClass -// try the following line instead -// public class MyClass -{ -} - -public class MyClass2 : MyClass // CS0060 -{ - public static void Main() - { - } -} -``` - +Inconsistent accessibility: base class 'Class1' is less accessible than class 'Class2' + +In C#, a derived class cannot have broader accessibility than its base class. If the base class is less accessible, consumers of the derived class might unintentionally gain access to a class they shouldn't see. + +Subclasses can never be more accessible than their base classes. That would allow consumers of the subclass broader access to the base type than was intended. + +The following sample produces CS0060 because `Class1` is `internal` and `Class2` is `public`. + +```csharp +internal class Class1 +{ +} + +public class Class2 : Class1 // 🛑 CS0060: Class1 is less accessible +{ +} +``` + +You can resolve CS0060 in one of two ways: + +- Make the base class more accessible: Change `Class1` to be `public`. +- Restrict the derived class's accessibility: Change `Class2` to be `internal`. + +> [!TIP] +> Base classes can be _more_ accessible than their subclasses, but never _less_ accessible. + ## See also - [Access Modifiers](../programming-guide/classes-and-structs/access-modifiers.md)