omit the pirvate/public etc

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

If you omit private / public / protected etc in a declaration then What is
it ? pirvate, protected ?

eg:
bool test;
bool check
{
return (something == false);
}
 
The default depends upon what you are declaring:

http://msdn.microsoft.com/library/d...y/en-us/csspec/html/vclrfcsharpspec_3_5_1.asp

"...when a member declaration does not include any access modifiers,
the context in which the declaration takes place determines the default
declared accessibility.

"Namespaces implicitly have public declared accessibility. No access
modifiers are allowed on namespace declarations.
"Types declared in compilation units or namespaces... default to
internal declared accessibility.
"Class members... default to private declared accessibility.
"Struct members... default to private declared accessibility because
structs are implicitly sealed.
"Interface members implicitly have public declared accessibility. No
access modifiers are allowed on interface member declarations.
"Enumeration members implicitly have public declared accessibility. No
access modifiers are allowed on enumeration member declarations.
 
Wilfried Mestdagh said:
If you omit private / public / protected etc in a declaration then What is
it ? pirvate, protected ?

It's always the most private it can be - so for top-level types it's
internal, for member variables it's private, etc.

This is a really good default setting, as it means you can omit the
access modifier and be on the safe side - any access modifier means
that you're deliberately making it more public.
 
Back
Top