Saturday, 4 June 2016

C# Classes And Objects

C# classes, It is basically a wrapper or a construct which group together methods, variables or properties. And Object is instance of class. We can create as many instance of class with new keyword. Object has attributes and behavior and these attribute and behavior is defined by a class.

For example : - Suppose you have a TV(Television). It is an object and its size, color is its attributes and its functions like volume up down or number of channels is its behavior. 
Same in case of c# classes and object. Classes instance is an object and its attribute and behaviour is defined by a class.

Class A
{
   int a= 4;
   int b=5;
   int c=0;
   public void Add()
  {
     c= a+b;
  }
   main//Main method
  {
     A instance1 = new A(); //Here can create as many as objects/instance you need
     A instance2 = new A();
  }
}




No comments:

Post a Comment