Member-only story
C# Classes and Objects with Examples
A class is basic pillar of OOP that is called when instance of a class is created. A class can have fields, properties, method, constructor and destructor etc. When we create an instance of class. This instance of class is used to access of fields, methods, properties, constructor (constructor can zero argument or multiple argument) and destructor. A class is reference type and stores in heap.
Declaration and Initialization:
Data Member Declaration:
You declare an attribute and variable of class in such way.
Example
// Fields (attributes or variables)
private int FruitPrice;
private string FruitName;
private bool FruitIsInMarket;
Data Member Initialization:
You can initialize an attribute and variable of class in such way.
Example
// Initializing data member of class
FruitPrice = 100;
FruitName = Mango;
FruitIsInMarket = Yes;
Constructor In Class:
Constructor is special method that called when object/instance of class is created
Example
// Constructor
public Fruit(int price, string name, bool…