Saturday, 5 September 2015

static in c#.net

Static
static is a keyword that behaves like type modifier.
static works again oop and beyond the oops.
static member are guest for a class.
A static variable created only once in complete program whenever
class is invoked only when application is closed.
Example:-
class class1
{
public int a,b;
public static int c;
public static int count=0;
public class1()
{
count++
message box.show("convert.To string")
}






class1 ob1=new class();
class1.c=25;

upcasting,downcasting,boxing,unboxing

Up casting.

Conversion of child data type into parent data type is
known as up casting.

Downcasting.

Conversion of parent data type into child data type is
known as downcasting.

To execute downcasting process there is always need of
type casting method.

General syntax for downcasting.

(type)expression

ob2=(class2)ob1;

Boxing

Conversion of value type into object data type is known as boxing.

Object behave like a universal data type because of boxing.

Object obj;
obj="helow";
obj="7.5";

unboxing

conversion of object data type into value type is called unboxing.
To executing unboxing process we always need of type casting.

doubled=convert.to Double (obj);

Diference between structure and class.

Difference between structure and c lass.

structure1.variable of structure define as value type variable.

2.In case of structure compiler support static binding.

class

1.variable of class define as reference type variable.

In case of class compiler support dynamic binding.


Note=>in oops every class contain its own object or reference
or pointer in same class with name This.

This behave like owner of class.

Rules of oops

Rules of oops.

First rule=>

To access member of class from outside of class we have to create object of same class .

General syntax to create object of class.

class name object name=new class name();
class1 obj 1 = new class1();

class name object name();

Example=>

class1 customer 1;
customer cusID=new customer;

class class1
private int a,b;
public int c;
public void set data1()
{
a=5;b=7;c=9;
}
public void set data2 (int x,int y,int z)
{
a=x;
b=y;
c=z;
}
public void set data3(int a,int b,int c);
{
a=a;
b=b;
c=c;
}
second rule=>


Every object have three separate memory blocks.

class1 ob 1=new class1();
obj1.a=25;

class1 ob 2= new class1();
ob 2.b=5;
ob 2.set data z(10,20,30);

class1 ob 3=new class1();
ob 3.set data 3(100,200,300);


Class

class

class is a user defined data type it can contain following item into it.

1.data field
2.constructor.
3.destructor.
4.property.
5.member function.
6.indexer.
7.delegate.
8.event.
9.attribute.

Theory of class.

1.Within class theory.
2.outside class theory.


=>To access member of class within same class is apart of within class theory.
In within class theory there is no role of any access specifier.

=>Outside of class exisibility of member is covered under outside theory.

keyword for overriding

keywords for overriding.

1)Virtual=overridable.

By default all methods are overridable.

2)Override=overrides.

If we are using override keyword with a function
then this override keyword also more functions as virtual.

3)Sealed=not overidable.

4)Abstract=must overridable.

*Abstract method must contain in abstract class.

*A method followed by abstract keyword is known as
abstract method.

It has following limitation.

1. Abstract method must contain in abstract class.

2. Abstract method do not contain definition.It
contain only signature of method.