C#
Hi all,
I pass an object to a method.
I want to cast that object to its specific class so I can perform its own specific methods? How can I do that?
Move( new Cat() );
Move( new Pigeon() );
public void Move(object objectToMove)
{
if(objectToMove== Cat)
{
Cat catObject = objectToMove as Cat;
catObject.Walk();
}
else if(objectToMove== Pigeon)
{
Rat pigeonObject = objectToMove as Pigeon;
pigeonObject.Fly();
}
}