Re: Knowing an object implements an Interface



Ron M. Newman wrote:

Hi,

Is there a quick way to know if a given object implements IComparable?
(without casting or anything like that). Something that uses reflection?

Thanks
-Ron

Hi Ron,

You can use the 'is' operator to test whether or not the given object will
cast to the given type:

if ( obj is IComparable ) { ... }

'obj is IComparable' will evaluate to true if obj can be cast to an
IComparable, i.e. if it implements the IComparable interface.

--
Hope this helps,
Tom Spink
.



Relevant Pages