Connecting Tech Pros Worldwide Forums | Help | Site Map

C# interfaces

William F. Robertson, Jr.
Guest
 
Posts: n/a
#1: Nov 17 '05
This is probably a more C# language question, but how can I tell if an
object implements a certain interface?

bill



Chris J. Breisch
Guest
 
Posts: n/a
#2: Nov 17 '05

re: C# interfaces


On Wed, 2 Jul 2003 10:49:48 -0500, William F. Robertson, Jr.
<wfrobertson@kpmg.com> 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
[color=blue]
> This is probably a more C# language question, but how can I tell if an
> object implements a certain interface?
>
> bill
>
>
>[/color]



--
Chris J. Breisch, MCSD.NET, MCDBA
[Gauthier]
Guest
 
Posts: n/a
#3: Nov 17 '05

re: C# interfaces


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" <cjbreisch@yahoo.com> wrote in message
news:oprroyihlb6mljj1@news.microsoft.com...[color=blue]
> On Wed, 2 Jul 2003 10:49:48 -0500, William F. Robertson, Jr.
> <wfrobertson@kpmg.com> 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
>[color=green]
> > This is probably a more C# language question, but how can I tell if an
> > object implements a certain interface?
> >
> > bill
> >
> >
> >[/color]
>
>
>
> --
> Chris J. Breisch, MCSD.NET, MCDBA[/color]


Closed Thread