Class in .Net - DotNet and DataBase

Wednesday, 11 July 2018

Class in .Net

A class is a collection of properties, methods,variables and constructors.
We can assume it as a blue print or template.

Let us suppose a car is there. It should contain wheels, seats and engine etc..
Every car should have these all features. So we assume car is a class.

So, Indica is a car, which contains wheels, seats and engine etc.. So,Indica is the object of the car blue print.

Here Indica is an object which represents the car class and its features or  characteristics are the members of the car class.

<Access specifier> Class <Classname>

Create an object to a class

Classname object = new Classname();

Using above class object can be created as below

program prg = new program();

Object is a representative of the class which shows the list of class members.
We can access the class members using the object created to that class.

Access specifier
Access specifier defines the scope of accessibility of a class members.
If it is public, we can use that class member across the program.

There are different types of access specifier in C#

1) Public
5)Protected internal

Note: We will discuss detail access specifier on "Access specifier post" soon.

A constructor is a special type of method which is used for initializing the values to the members of a class.
Constructor should not return a value. so, constructor declaration should not include any return type
and constructor name should  be the class name.
Constructor will be executed immediately when the object created to the class.

Access specifier Classname()

Using above class object can be created as below

public program

There are 5 types of classes in .NetFramework

Types of Classes
1)Concrete class
2)Sealed class
3)Abstract Class
4)Static Class
5)Generic class

No comments:

Post a Comment


Get Updates On

Discussion updates

Straight Into Your INBOX!

Enter your email address to subscribe to this website and receive notifications of new posts by email.