<ne*******@gmail.com> wrote in message
news:11*********************@h76g2000cwa.googlegro ups.com...
Hi all
maybe its just been a long day, but i have a question about call access
modifiers in C#. Consider the following code.
namespace Application
{
private class Class1
{
int i;
}
}
When I try to compile this i get the following error:
"Namespace elements cannot be explicitly declared as private,
protected, or protected internal"
When i make Class1 public i no longer get a compile error. Now correct
me if i'm wrong, but doesn't C# allow me to have private or protected
class structures? Am i missing something?
The definition of private is "Private members are accessible only within the
body of the class or the struct in which they are declared", so I guess it
makes no sense to declare something private if it's not within a class or
struct. Similarly protected only makes sense for a class member (but not a
struct member, since a struct cannot inherit from another struct). Thus I
think you can have private or protected classes, but only if they are nested
within another class/struct.
I also found this in the help: "Classes and structs that are not nested
within other classes or structs can be either public or internal. A type
declared as public is accessible by any other type. A type declared as
internal is only accessible by types within the same assembly. Classes and
structs are declared as internal by default unless the keyword public is
added to the class definition".
Chris Jobson