C# interfaces

Discussion in 'ASP .Net' started by William F. Robertson, Jr., Jul 2, 2003.

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

    bill
     
    William F. Robertson, Jr., Jul 2, 2003
    #1
    1. Advertising

  2. On Wed, 2 Jul 2003 10:49:48 -0500, William F. Robertson, Jr.
    <> 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
     
    Chris J. Breisch, Jul 2, 2003
    #2
    1. Advertising

  3. William F. Robertson, Jr.

    [Gauthier] Guest

    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" <> wrote in message
    news:eek:...
    > On Wed, 2 Jul 2003 10:49:48 -0500, William F. Robertson, Jr.
    > <> 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
     
    [Gauthier], Jul 3, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. shade
    Replies:
    1
    Views:
    1,672
  2. Ollie
    Replies:
    0
    Views:
    368
    Ollie
    Sep 9, 2003
  3. Kyle Fitzgerald

    Using Interfaces to control IDE property window

    Kyle Fitzgerald, Nov 4, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    314
    Kyle Fitzgerald
    Nov 4, 2003
  4. Oney
    Replies:
    1
    Views:
    3,195
    =?Utf-8?B?aWdvcms=?=
    Sep 24, 2004
  5. darrel
    Replies:
    0
    Views:
    323
    darrel
    Jan 21, 2005
Loading...

Share This Page