+ 6
In C#, are struct members private by default?
A SoloLearn quiz says Yes. A scan of the online Microsoft docs yielded nothing on this question.
5 Réponses
+ 6
Good reference. Thanks! For anyone else curious about this, the short answer seems to be:
"The access level for class members and struct members, including nested classes and structs, is private by default."
+ 2
Hey Eric... I was wondering about that when I came across this question some time ago. I was able to verify this using a quick test and I found documentation on this in:
- https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/access-modifiers
Section: Class and Struct Accessibility
> Struct members, including nested classes and structs, can be declared as public, internal, or private.
EDIT: I meant to paste this line from the link:
>The access level for class members and struct members, including nested classes and structs, is private by default.
+ 2
@Eric... You saw that too. I must have copied the wrong line not paying attention. I just noticed the line I used didn't answer your question. I'm glad you pulled the correct one from the link.
0
Yes in C# Language the default access level of members of Struct type is Private.
0
The access level for class members and struct members, including nested classes and structs, is private by default. Private nested types are not accessible from outside the containing type.
http://csharp.net-informations.com/language/csharp-access-specifiers.htm