Tutorial :in c# are methods private by default?



Question:

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?


Solution:1

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.


Solution:2

Yes, it is private.


Solution:3

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


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »