+ 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.

10th Dec 2017, 5:44 AM
Eric Blinkidu
Eric Blinkidu - avatar
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."
10th Dec 2017, 8:02 AM
Eric Blinkidu
Eric Blinkidu - avatar
+ 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.
10th Dec 2017, 5:55 AM
David Carroll
David Carroll - avatar
+ 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.
10th Dec 2017, 8:06 AM
David Carroll
David Carroll - avatar
0
Yes in C# Language the default access level of members of Struct type is Private.
17th Jul 2018, 7:53 PM
Ammar The Trainer
Ammar The Trainer - avatar
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
7th Jan 2020, 6:43 AM
rahul kumar
rahul kumar - avatar