check for interface implementation
Published: 15. February 2012 | Updated: 15. February 2012License: Microsoft Public License (MS-PL)
Categories: Framework » Basics
Tags: Basics C#
object obj = GetObject(); // throws an InvalidCastException when 'obj' doesn't implement IDisposable interface IDisposable disposable = (IDisposable)obj; // never throws an exception IDisposable disposable = obj as IDisposable; // returns indication whether 'obj' has implemented IDisposable interface bool implemented = obj is IDisposable;
| Send us feedback about this snippet » |





