I can not understand the concept of a method that doesn't have access modifiers. What are they for? What is the use to not put access modifiers?
5 Answers
A method doesn't have access modifiers written means it has a default modifier: private

- 18,436
- 5
- 23
- 42
-
this can't be right. Private can't always be the default. – dragonfly02 Feb 10 '19 at 15:59
-
Always, except microsoft changes the standard some day. https://github.com/dotnet/csharplang/blob/master/spec/basic-concepts.md#declared-accessibility – shingo Feb 10 '19 at 16:06
-
This standard will never change, as this would be a major braking change in C#. – Olivier Jacot-Descombes Feb 10 '19 at 16:48
In .NET, methods have default access modifier so you don't always have to specify them explicitly but it's considered a very bad practice not to explicitly specify them. See here for the default access modifier for different methods.

- 3,403
- 32
- 55
All types and type members have an accessibility level, which controls how they can be used, the following tutorial may help you to get a better grasp of C# modifiers.

- 898
- 2
- 12
- 23
if there is no access modifier written with a method it means its private by default This is a public Mehtod
public void Yourmethod()
{
}
This is a private Method by default
void Yourmethod()
{
}

- 155
- 1
- 2
- 9
A class member without access modifier is private. I.e., it is only visible within the class itself.
Example:
public class Test
{
public void Hello()
{
Print("Hello");
Print(" ");
Print("World");
}
void Print(string s)
{
Console.Write(s);
}
}
In this example the Print
method is not public, but can be called from within a method that is public
.
var test = new Test();
test.Hello(); // Works.
test.Print("bye"); // Not possible - compiler error!
I prefer to explicitly declare the members as private and to write the private
modifier, but this is up to you:
private void Print(string s)
{
Console.Write(s);
}

- 104,806
- 13
- 138
- 188