C# Class

Last modified: July 11, 2021

A class is a blueprint of a specific object.  An object is an instance of a class, and methods and variables made a class are called members of a class.

Let take a real-world example, a car. Every car has certain properties such as the colour of the car, top speed, manufacturer and common method/action such as start the car, brake the card, stop the car and open a door. Any manufacturer of a car that meets those requirements is an object of the class car.

The same applies to object-oriented programming where a class define properties, methods and so on.

The structure of a class is like below

<access specifier> class class-name { <access specifier> <data type> variable1; <access specifier> <return type> methodA(parameter-list) { } }
public class Car { public string modelName { get; set; } public int yearOfReleased { get; set; } private int door; public void Start() { //start the engine } public bool OpenDoor(int whichDoor) { door = whichDoor; return true; // the requested the door is open } }

project