Reputation: 2156
I've started learning C++ in my spare time and have noticed a cool gadget :
From C++ for Dummies page 176:
class SavingsAccount
{
public:
unsigned accountNumber;
double balance;
}
From my understand, this should declare all members below it as public
.
My question is : Is there something like this in C# ?
Upvotes: 2
Views: 1834
Reputation: 149558
In C#, scope is declared per class/struct member, not globally like C++.
There are default scopes, if none is explicitly declared.
The topic is covered on MSDN:
Classes and structs that are declared directly within a namespace (in other words, that are not nested within other classes or structs) can be either public or internal.
Internal is the default if no access modifier is specified. Struct members, including nested classes and structs, can be declared as public, internal, or private.
Class members, including nested classes and structs, can be public, protected internal, protected, internal, or private. 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.
Derived classes cannot have greater accessibility than their base types. In other words, you cannot have a public class B that derives from an internal class A. If this were allowed, it would have the effect of making A public, because all protected or internal members of A are accessible from the derived class.
Upvotes: 6