Classes are not called, only methods are called. At most it is calling the constructor that instantiates the class and the object is stored in the variable, in general indirectly.
If you’re talking about where declare the variables that will sustain the instance, there is no predefined right place, it is used where you have to use it. It can be in the class, it can be within a method, if your lifespan must be local.
If it goes at the beginning of the class, in the middle, at the end, before or after something, if everything goes scattered, little or nothing matters. It’s a question of organization and taste. It’s very common to do it early on, but not everyone follows it, and there may be cases where it’s better to do it differently.
There is no technical requirement, the initialization order cannot be defined within the class, only within methods.
It is common to group all private members, then group the properties. Static members are also usually grouped. There are those who like it until using #region
, but "most" prefer to avoid this.
If you need a lot of organization it’s likely that the class is doing too much stuff.
Several variables of the class Manutenção_cliente
are being initialized when an instance of this class is created. It seems to be a wise decision for this case.
In some cases some members may need to be initialized within the builder, common when one needs a specific order or needs to initialize other parts of the instances that cannot be easily done in the variables (needs later member initialization), or some specific processing. In much rarer cases you may need to initialize in some "normal" method, but this is a danger because the class will possibly be in invalid state.
This code does not follow the C nomenclature standard#. It also uses public or at least internal members (standard visibility), which should normally be avoided, but not at all costs, need to know when to do or not.
"Some people even like it
#region
, but most people prefer to avoid that." Why?– ramaral
@ramaral clica no link who has an answer that talks more in detail about this.
– Maniero