Normally I do this:
if (Animal is Dog)
{
Doc d = (Dog)Animal;
// d. etc..
}
else if (Animal is Cat)
{
Cat c = (Cat)Animal;
// c. ....
}
Is this a good way or are there better ways to implement this code above (performance, ...) ?
Should it be like this?:
Dog d = Animal as Dog;
if (d != null;)
{
// d. etc..
}
else if (Animal is Cat)
{
Cat c = (Cat)Animal;
// c. ....
}
Or maybe like this?:
Dog d = Animal as Dog;
Cat c;
if (d != null;)
{
// d. etc..
}
else if ((c = Animal as Cat) != null)
{
// c. ....
}
Or maybe something else?