Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a method called if you do not use an access identifier?

Tags:

c#

I do not know what a method without an access identifier is called. In this code block, I am referring to the void updateNumTo5 method.

private int num = 0;

#region public methods
public int Get7()
{
    return 7;
}
#endregion

#region private methods
private int get6()
{
    return 6;
}
#endregion

#region Unknown name
void updateNumTo5()
{
   num = 5;
}
#endregion
like image 570
BenR Avatar asked Dec 12 '22 20:12

BenR


1 Answers

The default access modifier (not identifier) is private for methods. So this:

private void Foo()
{
}

is equivalent to

void Foo()
{
}

The general rule is that the default access modifier is always the most restricted you could specify it as. So for example, non-nested types are internal by default, whereas nested types are private by default.

like image 129
Jon Skeet Avatar answered Feb 02 '23 10:02

Jon Skeet