Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > C# interfaces

Reply
Thread Tools

C# interfaces

 
 
William F. Robertson, Jr.
Guest
Posts: n/a
 
      07-02-2003
This is probably a more C# language question, but how can I tell if an
object implements a certain interface?

bill


 
Reply With Quote
 
 
 
 
Chris J. Breisch
Guest
Posts: n/a
 
      07-02-2003
On Wed, 2 Jul 2003 10:49:48 -0500, William F. Robertson, Jr.
<(E-Mail Removed)> wrote:


Since you mentioned C#, I'll give my answer in C#.


if (o is IMyInterface) {
// object o implements IMyInterface
}
else {
// object o doesn't implement IMyInterface
}

-chris

> This is probably a more C# language question, but how can I tell if an
> object implements a certain interface?
>
> bill
>
>
>




--
Chris J. Breisch, MCSD.NET, MCDBA
 
Reply With Quote
 
 
 
 
[Gauthier]
Guest
Posts: n/a
 
      07-03-2003
Hello,

there is also the 'as' keyword:

IMyInterface i = o as IMyInterface
if(i != null)
{
// i implements IMyInterface
}
else
{
// i does not implements IMyInterface
}

it allow you to bypass the cast that you need to put when using 'is' keyword

Now my question: Is there any fundamental diference between these 2 ways to
do slighty the same thing?

Gauthier

"Chris J. Breisch" <(E-Mail Removed)> wrote in message
news(E-Mail Removed)...
> On Wed, 2 Jul 2003 10:49:48 -0500, William F. Robertson, Jr.
> <(E-Mail Removed)> wrote:
>
>
> Since you mentioned C#, I'll give my answer in C#.
>
>
> if (o is IMyInterface) {
> // object o implements IMyInterface
> }
> else {
> // object o doesn't implement IMyInterface
> }
>
> -chris
>
> > This is probably a more C# language question, but how can I tell if an
> > object implements a certain interface?
> >
> > bill
> >
> >
> >

>
>
>
> --
> Chris J. Breisch, MCSD.NET, MCDBA



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
WZCSAPI/WZC-interfaces in VB.NET Jake Wireless Networking 3 06-10-2006 08:29 PM
Connecting two 1601's back-to-back via serial interfaces Cyber-Soldier Cisco 1 11-20-2003 07:49 PM
Cmenu, Text Interfaces, and UTF8 shade Perl 1 08-11-2003 11:24 AM
Re: Maximum VLAN interfaces PIX515-UR Patrick Cisco 0 07-25-2003 11:58 AM
Use private IP on inside interfaces of transit routers mliu Cisco 5 07-15-2003 08:53 PM



Advertisments