I do not know if it's clear to you what this modifier does. I recommend reading What is the difference between modifiers public, default, protected and private? , which indicated you in the comments. There it explains well. Basically, by declaring private
, its property or method is not seen or modified outside of the class where it is declared. Like public
, it can be viewed from the outside. As protected
, it can only be seen from objects that inherit from the current class.
About not using any access modifiers, as in your example: in C # this is equivalent to declaring as private
(in the case of properties or methods):
The access level for class members and struct members, including nested classes and structs, is private by default.
( The access level for members of classes and structs, including nested classes and structs, is private
by default .)
That is, it's the same. As a general rule, if you do not indicate what kind of access the member can have, it will be considered as restrictive as possible. However, this may not be clear to anyone reading your code. With this in mind, it is always recommended to explicitly use the access modifier.