Reputation: 1736
If I have a method that does not specify its Accessibility Level will it be Private by default?
void Item_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
throw new NotImplementedException();
}
Is the above method private?
Upvotes: 42
Views: 21260
Reputation: 1132
Yes, for methods, like your example.
Class and struct members, including nested classes and structs, have private access by default.
But that is not correct for all the access modifiers:
Classes, records, and structs declared directly within a namespace (in other words, that aren't nested within other classes or structs) can be either public or internal. internal is the default if no access modifier is specified.
I consider this a good idea, because by default in OO, everything should be private and only what is really needed should be marked public.
Upvotes: 0
Reputation: 4886
For a method inside a class, default is private. It does vary based on the scope of where things are declared, here's an MSDN link with more specifics
Upvotes: 4
Reputation: 41243
It is. The general rule if you don't define any modifier is "the most restricted modifier that can be applied here is used", so private for methods, internal for top-level classes, etc.
Upvotes: 69