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

28th Nov 2017, 4:51 AM
Adi Pratama
Adi Pratama - avatar
4 ответов
+ 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)!
28th Nov 2017, 5:02 AM
Schindlabua
Schindlabua - avatar
+ 1
what group?
24th Dec 2017, 5:14 AM
Duy Nguyễn
Duy Nguyễn - avatar
- 1
Hi :)
29th Nov 2017, 6:10 PM
OrderCompany
OrderCompany - avatar
- 15
do you guys wanna learn with me on a grup chat facebook ? i feel so lonely :,(
28th Nov 2017, 8:01 PM
Python O.T.P
Python O.T.P - avatar