What is class with example
In this article I'm going to explain What is class with example.
What is Class?
Class is simply a representation of a type of object. It is the template / blue print that describe the detail of an object.
Class is a group of related methods and variables. The class can have any of the following members.
Class are reference type. Classes will support inheritance.Classes can have explicitly parameterless constructors.
Member variable initialization is possible in class.It is possible to declare destructor in class.
1) Fields
2) Properties
3) Method
4) Events
5) Constructors
6) Destructor
7) Delegates
8) Indexers
Method:-
Methods are used to perform some task.
Constructors:-
Same name as class name its called Constructors.
Fields :-
A field is the variable created within the class and its used to store data of the class.
Properties:-
Properties are used to provide access to ther private fields of the class.A property contains two accessors, get and set
Class Example:-
using System;
class PerlClassExample
{
string _name;
public PerlClassExample()
{
// Assign this._name
this._name = "Kumar";
// Assign _name
_name = "Rengan";
// The two forms reference the same field.
Console.WriteLine(this._name);
Console.WriteLine(_name);
}
}
class ExampleProgram
{
static void Main()
{
PerlClassExample objectPerlClassExample = new PerlClassExample();
}
}
Output
Renngan
Rengan