2010/03/05

C# week6_3


03/03/2010

 
int i;
int i1, i2;
i1 = 5;
i2 = 7;
i1 = i2;
i15
i2 7
i1 is assigned i2 stored value.
Reference = Parse

 
class A { }
A a1 = new A();
A a2 = new A();
a1 = a2; (It will work.)
a1 is assigned address of a2Memory Location.
a1 memory location is not used by any object.

 
Garbage Collector: used free on memory location
If you want Garbage Collector to collect memory, you should write on your program.

 
class A { }
class B { }
A a1 = new A;
B b1 = new B;
a1 = b1; (error)
It means you assign different data type.

 
class A { }
A a1, a2;
a1 = new A();
a2 = new A();
a1 = a2;
Once you assign a1 to a2, you can't back.

 
class A { }
class B { }
A a1,a2,a3;
a1 = new A();
a1 = null; (remove memory location)

 
Parents valuable can refer child object.
class B
class A : B
Parent B b = new B();
child A a = new A();
b = a; (OK)
a = b; (error)

 
Polymorphism: more than one behaviour
class A
{
public virtual void abc()
{
}
}
class B : A
{
override public void abc()
{
}
}
A a = new B(); (B is initialized)
a.abc();

0 件のコメント:

コメントを投稿

UA-9417263-1