Ask a Question related to ASP.NET General, Design and Development.

  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


    William F. Robertson, Jr. Guest

  2. Similar Questions and Discussions

    1. Custom interfaces
      Hi. My web service class implements a custom interface. When I see the service description, my custom interface is not there. In my client, I...
    2. Interfaces and webservices
      VB.NET Hi Im writing a windows form that talks to its business layer via web services. I want to define an interface that both client and web...
    3. Interfaces And Web Services
      Hi, Im having a little trouble with the fiollowing in a web service Public Interface IBookAttribute Property Description() As String End...
    4. [PHP-DEV] problem with interfaces
      Hi all, Is this supposed to work? interface test { function my_function ($mandatory_parameter); } class test_class implements test {...
    5. IPSec Interfaces
      This is my second posting as I took all the advice on the first and it helped a bit but I'm still getting errors on my Event Log. My IPSec can't...
  3. #2

    Default 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
    > 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

  4. #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@yahoo.com> wrote in message
    news:oprroyihlb6mljj1@news.microsoft.com...
    > 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
    >
    > > 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

Posting Permissions

  • You may not post new threads
  • You may 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