Docs: Error on page describing access modifiers (private and private protected)

Created on 4 Oct 2018  Β·  8Comments  Β·  Source: dotnet/docs

@miksarus commented on Tue Oct 02 2018

НС ΠΊΠΎΡ€Ρ€Π΅ΠΊΡ‚Π½ΠΎ ΡƒΠΊΠ°Π·Π°Π½ΠΎ описаниС ΠΌΠΎΠ΄ΠΈΡ„ΠΈΠΊΠ°Ρ‚ΠΎΡ€ΠΎΠ² доступа Π½Π° страницС. Private - ΠΌΠΎΠ΄ΠΈΡ„ΠΈΠΊΠ°Ρ‚ΠΎΡ€ доступа относящийся Ρ‚ΠΎΠ»ΡŒΠΊΠΎ ΠΊ Ρ‡Π»Π΅Π½Π°ΠΌ ΠΈ ΠΊ Ρ‚ΠΈΠΏΡƒ ΠΏΡ€ΠΈΠΌΠ΅Π½ΡΡ‚ΡŒΡΡ Π½Π΅ ΠΌΠΎΠΆΠ΅Ρ‚. Π’ΠΎ ΠΆΠ΅ самоС касаСтся ΠΈ private protected.


@LisandroSu commented on Tue Oct 02 2018

ЗдравствуйтС, @miksarus !

Π‘Π»Π°Π³ΠΎΠ΄Π°Ρ€ΠΈΠΌ Вас Π·Π° прСдоставлСнный ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΉ. ΠšΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΈ ΠΏΠΎΠΌΠΎΠ³Π°ΡŽΡ‚ Π½Π°ΠΌ постоянно ΡƒΠ»ΡƒΡ‡ΡˆΠ°Ρ‚ΡŒ ΠΏΠΎΡ€Ρ‚Π°Π» docs.microsoft.com. Однако Π½Π°ΠΌ Π½Π΅ΠΎΠ±Ρ…ΠΎΠ΄ΠΈΠΌΡ‹ Π΄ΠΎΠΏΠΎΠ»Π½ΠΈΡ‚Π΅Π»ΡŒΠ½Ρ‹Π΅ свСдСния, Ρ‡Ρ‚ΠΎΠ±Ρ‹ ΠΏΡ€ΠΎΠ°Π½Π°Π»ΠΈΠ·ΠΈΡ€ΠΎΠ²Π°Ρ‚ΡŒ Π’Π°Ρˆ ΠΎΡ‚Π·Ρ‹Π². НС ΠΌΠΎΠ³Π»ΠΈ Π±Ρ‹ Π’Ρ‹ Π΄Π°Ρ‚ΡŒ Π±ΠΎΠ»Π΅Π΅ ΠΏΠΎΠ΄Ρ€ΠΎΠ±Π½ΡƒΡŽ ΠΈΠ½Ρ„ΠΎΡ€ΠΌΠ°Ρ†ΠΈΡŽ ΠΈ ΠΏΠΎΡΡΠ½ΠΈΡ‚ΡŒ свой ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΉ?

Π‘ ΡƒΠ²Π°ΠΆΠ΅Π½ΠΈΠ΅ΠΌ,
ΠœΠ΅ΠΆΠ΄ΡƒΠ½Π°Ρ€ΠΎΠ΄Π½Π°Ρ ΠΊΠΎΠΌΠ°Π½Π΄Π° MicrosoftΒ DOCS


@miksarus commented on Wed Oct 03 2018

@LisandroSu, ΠΏΡ€ΠΎΡˆΡƒ прощСния. Π― Π΄ΡƒΠΌΠ°Π» ΠΏΠΈΡˆΡƒ ΠΎ ΠΊΠΎΠ½ΠΊΡ€Π΅Ρ‚Π½ΠΎΠΉ страницС, Π° ΠΏΠΎΡ…ΠΎΠΆΠ΅ написал ΠΎ всСй Π΄ΠΎΠΊΡƒΠΌΠ΅Π½Ρ‚Π°Ρ†ΠΈΠΈ.
Π Π΅Ρ‡ΡŒ Π±Ρ‹Π»Π° ΠΎΠ± этом Π΄ΠΎΠΊΡƒΠΌΠ΅Π½Ρ‚Π΅: https://docs.microsoft.com/ru-ru/dotnet/csharp/programming-guide/classes-and-structs/access-modifiers

Π‘ΠΊΡ€ΠΈΠ½ΡˆΠΎΡ‚: https://yadi.sk/i/cA7xBDvI1uW07w


@LisandroSu commented on Wed Oct 03 2018

ЗдравствуйтС, @miksarus !

Бпасибо Π·Π° ΠΎΡ‚Π·Ρ‹Π².

ΠœΡ‹ Π°ΠΊΡ‚ΠΈΠ²Π½ΠΎ просматриваСм ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΈ ΠΈ скоро ΠΎΡ‚Π²Π΅Ρ‚ΠΈΠΌ Π’Π°ΠΌ.

Π‘ Π½Π°ΠΈΠ»ΡƒΡ‡ΡˆΠΈΠΌΠΈ поТСланиями,
ΠœΠ΅ΠΆΠ΄ΡƒΠ½Π°Ρ€ΠΎΠ΄Π½Π°Ρ ΠΊΠΎΠΌΠ°Π½Π΄Π° ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΊΠΈ Π΄ΠΎΠΊΡƒΠΌΠ΅Π½Ρ‚Π°Ρ†ΠΈΠΈ ΠœΠ°ΠΉΠΊΡ€ΠΎΡΠΎΡ„Ρ‚

Area - C# Guide Technology - C# Language Reference P1 Pri3 doc-bug

All 8 comments

Hi team,
According to the bug reporter, "private" and "private protected" access modifiers can be applied to members only, not to types. Can you please check on this?

Thanks!

@LisandroSu, I have wrote this, because on the page https://docs.microsoft.com/ru-ru/dotnet/csharp/language-reference/keywords/private wrote that private can be applied only for members

VS 2017 say:
"Elements defined in a namespace cannot be explicitly declared as private, protected, protected internal, or private protected"
My experiment screenshot: https://yadi.sk/i/cwOW8T_NvHIyEw

@LisandroSu @miksarus types can be nested, that is, declared inside another type. Nested types can be private or private protected.

The following example (note that classes A and B are declared inside the Program class):

using System;

public class Program
{
  public static void Main()
  {
    Console.WriteLine(new A());
    Console.WriteLine(new B());
  }

  private class A
  {
    public override string ToString() => "Private class";
  }

  private protected class B
  {
    public override string ToString() => "Private protected class";
  }
}

compiles and produces the following output:

Private class
Private protected class

There might be a question to following wording:

Private members are accessible only within the body of the class or the struct in which they are declared

What does "member" mean? In particular, does it include type notion? According to the class keyword article:

A class can contain declarations of the following members:
...
Classes
Interfaces
Structs
Enumerations

So, member can be a type.

Moreover, the same page contains the following paragraph:

Class members, including nested classes, can be public, protected internal, protected, internal, private, or private protected.

@pkulikov in my opinion if type was implemented inside another class it is member. it can be called "type-member" (to be honest, i don't know how it can be translated from Russian). This class is nested, so it can be called "nested-type".
In the other hand, our student-junior, was confused after reading the documentation. And this spurred him to make some experimenting with the code to better understand meaning of access modifiers.

Do I understand it correctly that this issue is about the following text (and similar texts for the other modifiers)?

private
The type or member can be accessed only by code in the same class or struct.

I think this text is technically correct, but confusing, because the only case when a type can have the private modifier is when it's also a member.

At the same time, I think the following sections explain this well, and that the distinction about which modifiers can be used in which situations shouldn't be made here.

So, maybe it would be better if the text avoided "type or member" altogether and was changed to something like the following?

private
The target can be accessed only by code in the same class or struct.

I'm not completely happy to use "the target" here, but I could not think of a better word or phrase to use here.

@svick what about dropping "or" and saying

The type member...

Or

The member of a type...

@pkulikov That would not be correct for public and internal, which are also valid for types that are not type members (i.e. non-nested types). And I think it would be better if all modifiers used the same wording in this list.

By the way, wording in the reference section is shorter and avoids using confusing "type or member":
https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/access-modifiers

I would remove the whole list and reference the article from the c# reference. Maybe, the whole article can be merged into the reference section, even.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

LJ9999 picture LJ9999  Β·  3Comments

ike86 picture ike86  Β·  3Comments

stjepan picture stjepan  Β·  3Comments

LJ9999 picture LJ9999  Β·  3Comments

skylerberg picture skylerberg  Β·  3Comments