You can either throw it (which may throw an exception) or use the operator as.
private void DrinkIt(Object o) {
IDrink possibleDrink = o as IDrink;
if (possibleDrink == null)
Console.WriteLine("Not a drink!");
else {
ChugItDown(possibleDrink);
Console.WriteLine("That hit the spot!");
}
}
It doesn't matter how many interfaces are oimplemented - here you are just wondering if that is IDrink. If you want a complete list, you should use reflection ( System.Reflection):
Type [] interfaces = myObject.GetType().GetInterfaces();
, myObject null - null . , interfaces IDrink, IEat ..