Mega Code Archive

 
Categories / C# Tutorial / Class
 

The General Form of a Class

A class is created by use of the keyword class. The general form of a class definition that contains only instance variables and methods: class classname {     // declare instance variables     access type var1;     access type var2;     // ...     access type varN;          // declare methods     access ret-type method1(parameters) {         // body of method     }     access ret-type method2(parameters) {         // body of method     }     // ...     access ret-type methodN(parameters) {         // body of method     } } The general form for declaring an instance variable is shown here: access type var-name; access specifies the access, type specifies the type of variable, and var-name is the variable's name. To access these variables, you will use the dot (.) operator. The dot operator links the name of an object with the name of a member. The general form of the dot operator is shown here: object.member You can use the dot operator to access both instance variables and methods.