Is there a C # equivalent for access modifier areas in C ++

You can declare variables with the structure below in C ++

private: public: protected: float bla1; float bla2; float bla3; 

Is there an equivalent in C #? It seems rather tedious to repeat itself;

 protected float bla1; protected float bla2; protected float bla3; 
+3
source share
4 answers

No, no such. In fact, it is intended to make the code more readable. This applies to both C # and Java.

+8
source

No. Access is indicated in each ad.

The advantage of this is that the location of the method in the source file does not affect behavior. This means that you can move methods and properties with impunity (for example, link clan-related methods). The same is not entirely true for fields - it is possible to make a question about the ordering of field fields. Admittedly, itโ€™s better not to do this in the first place ...

+9
source

It is worth noting that if you have several members of the same type, you can declare them as:

 protected float bla1, bla2, bla3; 
+7
source

There is no equivalent in C # (also VB and F #).

Personally, I like this difference. I work on a very large base of C ++ code, and there is no way to look at a specific method and find out its special availability. Some of the classes have become so large that it takes a significant amount of page scrolling to see the modifier.

Some coders may think that this is not bad, but think about what happens when people start mixing in #if defs in the middle of the class and adding modifiers to these # if. This makes the definition of an access modifier during code verification a nontrivial operation.

This is a small print sacrifice for adding an inline modifier, but it is worth it to be able to read for a long time.

+1
source

All Articles