Hi,
Please give me some simple example for type conversion between two classes in C#
Thanks in advance
Sathish
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
sathishPosted Jan 27, 2014, 4:35 AM
Eric ZimmermanPosted Jan 23, 2014, 12:37 AM
One thing that comes to mind is base class + several derivatives...
e.g.
class AnimalBase;
class Donkey : AnimalBase
class Tiger : AnimalBase
void SomeFunction(AnimalBase animal)
{
if (animal is Tiger)
{
Tiger tiger = animal as Tiger;
tiger.DoSomethingTigerish();
}
}
VulpesPosted Jan 22, 2014, 9:46 AM
Jignesh TrivediPosted Jan 22, 2014, 7:41 AM
hi,
what do you mean by type casting between classes?
are you saying or looking solution for convert one class object to other class object?
so i think it is not possible you have to cast it property by property or you can use reflection.
hope this will help you.