Test if object implements interface

JoshRivers picture JoshRivers · Jan 4, 2009 · Viewed 213.5k times · Source

What is the simplest way of testing if an object implements a given interface in C#? (Answer to this question in Java)

Answer

Robert C. Barth picture Robert C. Barth · Jan 4, 2009
if (object is IBlah)

or

IBlah myTest = originalObject as IBlah

if (myTest != null)