Class in C#

How we Create and access class??

Class is a part of program it contains fields or variables and methods. Class are written in Computer Programs, that programming languages which are used to written classes are called Object Oriented Programming languages.

Classes are declared by using a keyword called "class".

  1. //access modifier //class //class-name  
  2. public class my-class

For example:

  1. Public Class Area; //Declaration of Class.  
  2. {  
  3.    Public int length; //initialization of Field.  
  4.    Public int breath; //initialization of Field.  
  5.    Public double Area (); // Declaration of method;  
  6.    {  
  7.       Return Area=length*Breath;  
  8.    }  

If we use class fields and method in program then we want to initialize it first.

  1. Circle c; // Create a Circle variable  
  2. c = new Circle (); // Initialize it 

OR

  1. Circle c = new Circle ();
Ebook Download
View all
Learn
View all