I do not know if it is clear to you what this modifier does. I recommend reading What is the difference between public, default, protected and private modifiers?, that you have indicated in the comments. There explains well. Basically, declaring private
, its property or method is not seen or modified from outside the class where it is declared. How public
, it can be seen from outside. How protected
, can only be seen from objects inherited from the current class.
About not using any access modifier, as in your example: in C# this is equivalent to declare 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 class members and structs, including nested classes and structs, is private
by default.)
That is, it gives anyway. As a general rule, if you do not indicate what type of access the member may have, it will be considered as restrictive as possible. However, this may not be clear to anyone reading your code. Thinking about it, it is always recommended to explicitly use the access modifier.
Possible duplicate of What is the difference between public, default, protected and private modifiers?
– Marquezani
I believe that the question is not duplicate, after I read the question better I understood the statement, I took the opportunity and edited the title to avoid confusion.
– Guilherme Nascimento
If you do not put anything, the compiler puts the private for you. That is, of the same.
– Francisco
@There is no reason to be bored with this, we are human, we all made mistakes, even the most experienced of the site has this right, we are not machines, just come and talk, outside that not only who closed failed, you could also have made a better/intuitive title. Who closed it wrong, who created the question wrong, all made mistakes, what matters is to arrive and talk and in your case edit to clarify better. Talking we’ll all come.
– Guilherme Nascimento
@Guilherme Nascimento De boa! (-:
– isaque