Private keyword vs without personal keyword

What is the use of the private keyword if everything is private by default?

public class A { object someObject; private object someOtherObject; } 

Wouldn't both of them be private? If they are both personal, then why do you need a keyword?

+8
c #
source share
4 answers

Explicit use of the keyword clarifies the code, no matter what the default is.

Avoid guesswork or the need for fact checking by the reader / maintainer code where possible.

There is a link to visibility information through this previous question .

+20
source share

As Steve Townsend said , he refines the code, but is also useful in mixed-access properties, for example:

 public int SomeProperty { get; private set; } 
+9
source share

The default value has changed from time to time. Previously, VB had everything that was public by default. Now it is closed.

In other programming languages, the default value is different.

So, writing it helps the code reader.

+3
source share

The purity of the code is next to Divinity. Easy to read.

+1
source share

Source: https://habr.com/ru/post/650094/


All Articles