//через as void UseOne2(One one) { Two two = (one as Two); if (two != null && two.SomeBool == false) { two.Display(); } else { Console.WriteLine("Преобразование не удалось"); } }
//через try catch void UseOne3(One one) { try { Two two = (Two)one; if (two.SomeBool == false) { two.Display(); } } catch (InvalidCastException e) { Console.WriteLine(e.Message); } }
// через is void UseOne1(One one) { if (one is Two) { Two two = (Two)one; if (two.SomeBool == false) { two.Display(); } } else { Console.WriteLine("Преобразование не удалось"); } }