c# method |
There are five class members who classify a class and
classes classify the objects which are.
1. Constructors
2. Methods
3. Destructors
4. Instance variable
5. Properties
CONSTRUCTOR:
A class member which is used to initialize
the object and it’s always come to early binding in a program means constructor
will declare if we have to assign values to the class before the creation of
class. It calls by the keyword ‘new’ to instantiate an Object.
Classname Obj = new constructor (
);
RULE TO BUILD CONSTRUCTOR
Assuming three rules to build
constructor also these points will keep an eye to identify the constructor in
any Object Oriented Program.
1. The name of constructor and Class name must be same.
2. A constructor never gives
any return type.
3. The constructor should always Public not Private.
TYPE OF CONSTRUCTOR
There are two type of constructor,
1. Default Constructor
2. Parametric Constructor
DEFAULT CONSTRUCTOR
This is
type of constructor which need not declare in Class because by default every
class has its own Default Constructor and write by its own basis. Default
Constructor haven’t a return type also haven’t any arguments or parameter.
SYNTAX
Public class Classname
{
Public void Classname
( )
{
Do this;
}
}
PARAMETRIC CONSTRUCTOR
Another
type of Constructor which hasn’t any return type but it accepts parameters. Parameter
is also known as argument.
SYNTAX
Public class Classname
{
Public void
Classname (int a, decimal b, double c)
{
Do this;
}
}
METHOD
Method is
also a class member which is used to build a class and it’s always come in late
binding, means method will declare if we have to give values to the class after
the creation of class.
IDENTITY OF METHOD
1. The method name and the class name should different.
2. Method may have return type or may not on the base requirement.
3. It can accept arguments.
SYNTAX
Public class Classname
{
Public returntype methodname (int a, decimal b,
double c)
{
Do this;
Return this;
}
}
DESTRUCTOR
When we
require to delete an existing Object from the memory of computer until there is
no need of that object we use Destructor to delete Objects.
INSTANCE VARIABLE
Instance variable
also often call Class variable. Instance variable is the class variable which
is used by the class only, in other word Instance variable is the private variable
of a class which can’t be accessible by outside of class.
RULE TO IDENTIFY A CLASS VARIABLE
1. Class variable always private
2. It only used in a specific class.
SYNTAX
Public class classname
{
int variable;
}
PROPERTIES
The last class member which is used to get and
set the values to the variable from outside of the Class. Get mean read a
variable and Set mean write a variable. Properties also a late binding method
we can change the variable by set keyword after the creation the Class. It should
be public always.
SYNTAX
Public int variblename{ get; set; }
Get more
0 comments:
Post a Comment
Please do not enter any spam link in the comment box