471,325 Members | 1,484 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,325 software developers and data experts.

Re: implement

J-L submitted this idea :
HI,

I don't find the method ro detect if a class implement an interface.

I try

if (MyObject implements MyInterface)

but it doesn't work.

if (MyObject is MyInterface)

work. Is it the only method to do that ?

J-L
the "is" operator works with both interfaces and (base)classes.
Basically it's "can I treat 'MyObject' as a 'MyInterface'".

A different way would be the "as" operator, which tries a cast but
gives a 'null' if it didn't work:
MyInterface mi = MyObject as MyInterface;
if (mi != null) ...

And if you really want to, you could also use reflection.

Hans Kesting
Jun 27 '08 #1
0 952

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Billy Porter | last post: by
4 posts views Thread by Peter | last post: by
13 posts views Thread by Sherif ElMetainy | last post: by
7 posts views Thread by moondaddy | last post: by
reply views Thread by emin.shopper | last post: by
5 posts views Thread by Tony Johansson | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.