Explicit Access Modifiers

Question
Should I omit access modifiers and accept the default when defining types and their members?

Answer
No, you’ll want to explicitly call out the scope for types and their members.

Comments
The default scope for type members in C# is private. Omitting access modifiers may confuse programmers coming to C# from other languages.

Example

// Not recommended.
void PerformTask() {
    ...
}

// This is preferred.
private void PerformTask() {
    ...
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s