"gökhan" <(E-Mail Removed)> a écrit dans le message de news:
(E-Mail Removed)...
If you are dealing with reference types, then you are not unboxing, you are
simply casting.
// a base class
class Vector{};
// inherited class
class VectorChild:Vector{};
class VectorChildChild:VectorChild{};
// some other class
class A
{
public void vectorfun(Vector a,Vector b){}
public override void fun(object a,object b) {
// ***********************
// my ugly solution....
// ***********************
if (typeof(Vector) == a.GetType() )
vectorfun( (Vector) a , (Vector) b); // unboxing to Vector
if (typeof(VectorChild) == a.GetType() )
vectorfun( (VectorChild) a , (VectorChild) b); // unboxing to
VectorChild
if (typeof(VectorChildChild) == a.GetType() )
vectorfun( (VectorChildChild) a , (VectorChildChild) b); //
unboxing to VectorChildChild
// ***********************
// ***********************
}
}
I would like to call the "fun" member of an instance of A
using Vector instances and VectorChild instances.
Then why have you got a method fun that takes objects, why not pass the
Vector/derivatives to the strongly typed method ?
public void vectorfun(Vector a,Vector b){}
....wil take any Vector, VectorChild or VectorChildChild object.
Joanna
--
Joanna Carter [TeamB]
Consultant Software Engineer