Accessing the right member based on the object type
<p>PlayerBase is a base class for FieldPlayer and GoalKeeper. I have stateMachine memeber in FieldPlayer and GoalKeeper. But in MyList a FieldPlayer and a GoalKeeper are both treated as PlayerBase. How do I make sure that I get the stateMachine for the right type? Should I somehow check for type and then typecast?   </p>

<pre><code>foreach (PlayerBase p in MyList)
{
 // Here I need to access p.stateMachine for FieldPlayer or GoalKeeper, depends what p is.
}
</code></pre>

<p>Thanks</p>
