Saturday, August 15, 2020

Classes and Objects in C#

 Classes

A building block of an application. 










Anatomy of a class is,

1. Data (Represented by fields)

2. Behavior (Represented by methods/functions)










Declaring a class










Class Members

1. Instance - Accessible from an object
         
          var person = new Person();
          person.Introduce();

2. Static - Accessible from the class

         Console.WriteLine(); // Console is the class and WriteLine is a static method. 

    No need to create a object of Console class by using new operator in order to call WriteLine method. 

Objects

Object is a blue print of a class. Also called an instance of a class. It has an identity, attributes and behavior. 











Creating an Object

To create objects, we use "new" operator. By using objects, we can access class fields and methods. 







A Simple Class 



No comments:

Post a Comment