Professional Web Applications Themes

C# interfaces - ASP.NET General

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

Sponsored Links
  1. #1

    Default C# interfaces

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

    bill


    Sponsored Links
    William F. Robertson, Jr. Guest

  2. #2

    Default Re: C# interfaces

    On Wed, 2 Jul 2003 10:49:48 -0500, William F. Robertson, Jr.
    <wfrobertsonkpmg.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
    > 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 Guest

  3. #3

    Default 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> wrote in message
    news:oprroyihlb6mljj1news.microsoft.com...
    > On Wed, 2 Jul 2003 10:49:48 -0500, William F. Robertson, Jr.
    > <wfrobertsonkpmg.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
    >
    > > 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] Guest

Similar Threads

  1. Custom interfaces
    By Robert Scheer in forum ASP.NET Web Services
    Replies: 3
    Last Post: April 19th, 02:50 PM
  2. Interfaces and webservices
    By Rob Thomson in forum ASP.NET Web Services
    Replies: 0
    Last Post: October 28th, 11:27 AM
  3. Interfaces And Web Services
    By Joe in forum ASP.NET Web Services
    Replies: 4
    Last Post: October 6th, 01:03 PM
  4. [PHP-DEV] problem with interfaces
    By Cristiano Duarte in forum PHP Development
    Replies: 0
    Last Post: August 31st, 03:56 PM
  5. IPSec Interfaces
    By Rob G in forum Windows Setup, Administration & Security
    Replies: 3
    Last Post: July 25th, 12:52 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139