Skip to content

Commit 208c82a

Browse files
drewnoakesBillWagnergewarren
authored
Update CS0060 documentation (#46917)
* Update CS0060 documentation Improve the documentation for CS0060 to be clearer about the cause of the issue, and how it can be resolved. Also explain that types may be made less accessible while subtyping, as the previous doc suggested they had to be the same ("consistent"). * Apply suggestions from code review Co-authored-by: Genevieve Warren <24882762+gewarren@users.noreply.github.com> --------- Co-authored-by: Bill Wagner <wiwagn@microsoft.com> Co-authored-by: Genevieve Warren <24882762+gewarren@users.noreply.github.com>
1 parent 10d680e commit 208c82a

File tree

1 file changed

+28
-24
lines changed

1 file changed

+28
-24
lines changed

docs/csharp/misc/cs0060.md

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,40 @@
22
description: "Compiler Error CS0060"
33
title: "Compiler Error CS0060"
44
ms.date: 07/20/2015
5-
f1_keywords:
5+
f1_keywords:
66
- "CS0060"
7-
helpviewer_keywords:
7+
helpviewer_keywords:
88
- "CS0060"
99
ms.assetid: ae6d4fb7-5ff9-4883-82c3-f55b190f439a
1010
---
1111
# Compiler Error CS0060
1212

13-
Inconsistent accessibility: base class 'class1' is less accessible than class 'class2'
14-
15-
Class accessibility should be consistent between the base class and inherited class.
16-
17-
The following sample generates CS0060:
18-
19-
```csharp
20-
// CS0060.cs
21-
class MyClass
22-
// try the following line instead
23-
// public class MyClass
24-
{
25-
}
26-
27-
public class MyClass2 : MyClass // CS0060
28-
{
29-
public static void Main()
30-
{
31-
}
32-
}
33-
```
34-
13+
Inconsistent accessibility: base class 'Class1' is less accessible than class 'Class2'
14+
15+
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.
16+
17+
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.
18+
19+
The following sample produces CS0060 because `Class1` is `internal` and `Class2` is `public`.
20+
21+
```csharp
22+
internal class Class1
23+
{
24+
}
25+
26+
public class Class2 : Class1 // 🛑 CS0060: Class1 is less accessible
27+
{
28+
}
29+
```
30+
31+
You can resolve CS0060 in one of two ways:
32+
33+
- Make the base class more accessible: Change `Class1` to be `public`.
34+
- Restrict the derived class's accessibility: Change `Class2` to be `internal`.
35+
36+
> [!TIP]
37+
> Base classes can be _more_ accessible than their subclasses, but never _less_ accessible.
38+
3539
## See also
3640

3741
- [Access Modifiers](../programming-guide/classes-and-structs/access-modifiers.md)

0 commit comments

Comments
 (0)