Yes
Casting doesn't change the nature of the object, just what you are "looking at it as". The cast will throw an InvalidCastException
if it isn't actually of that type (or inherits from that type), so be careful when doing this.
You could instead use the as
operator and check for null afterwards as a much safer way of casting. Either way, you can cast as much as you like and it won't cause any problems.
To try and explain why casting from Item
to Gun
is ok, think about it in pure English terms:
Say I hand you a bunch of Items. Those items are of many types, some of which are Guns. You pick an item at random (say its a Gun for arguments sake). You can safely treat it as an Item, a piece of Equipment, or a Gun. It doesn't matter which, as long as it actually is a gun. Of course, if you picked an apple, and tried to treat it as a gun, that could cause some problems (and hilarity :) ).