+ 41
Why elements defined in a namespace only can be explicitly declared as public?
program sample: https://code.sololearn.com/crUxoTHcA4Nx/#cs If i change class program as private, there's error message: "..\Playground\(12,17): error CS1527: Elements defined in a namespace cannot be explicitly declared as private, protected, or protected internal"
4 Answers
+ 20
Making a variable protected means that subclasses have access to it. A namespace is not a class though and you can't "subclass" it, so that makes no sense of course.
I can see why private seems like it should be an option, but then again, in C# you can spread your namespace over multiple files. So you can always get yourself access to private namespace variables if you need them, by adding a public method to the namespace that returns the private variable.
EDIT: and things get tricky across assembly boundaries. I can't imagine what a non-internal, private variable as seen from a different assembly would even do (or why you'd need that)!
+ 1
what group?
- 1
Hi :)
- 15
do you guys wanna learn with me on a grup chat facebook ? i feel so lonely :,(