Hi everyone. I'm just starting to learn about c#. I'm a C programmer to microcontrollers but I don't know anything about oriented object. I'm trying to develop a windows form with only one buttom. Everytime the buttom is pressed it shows in a message box how many times the buttom was pressed. The problem is that i have to declare the variable that will hold the number of times the buttom was pressed locally into the "buttom click"event and initialize that with zero. Then everytime the buttom is pressed and the event is serviced I would increment this variable by 1 and show in the message box. The problem is that the variable is initialized again and goes back to zero. I use to do this by using global variables that is a common practice in procedural programming. But it seems that there's no such thing in oriented object programming. Does anyone may help me find a solution ?
Best Regards
Lucio
VulpesPosted Apr 24, 2014, 10:41 AM
VulpesPosted Apr 24, 2014, 11:33 AM
'private' means that the variable (or other member) can only be accessed from within the class itself.
There are several other 'access modifiers' that can be used:
'public' means that the member can be accessed from anywhere.
'internal' means that the member can only be accessed from within the same program.
'protected' means that the member can only be accessed from within the current class or a class derived from it.
'protected internal' (or 'internal protected') means that the member can be accessed from within the current program or from a derived class.
If you don't specify an access modifier, then private is assumed for class members.
Types (classes, structs, enums etc) can also take access modifiers. If you don't specify one, internal is assumed.
Lucio SilveiraPosted Apr 24, 2014, 11:17 AM