HiveBrain v1.2.0
Get Started
← Back to all entries
patterncsharpCritical

Test if object implements interface

Submitted by: @import:stackoverflow-api··
0
Viewed 0 times
interfaceobjecttestimplements

Problem

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

Solution

if (object is IBlah)


or

IBlah myTest = originalObject as IBlah

if (myTest != null)

Code Snippets

if (object is IBlah)
IBlah myTest = originalObject as IBlah

if (myTest != null)

Context

Stack Overflow Q#410227, score: 688

Revisions (0)

No revisions yet.