instanceOf

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • rua17

    instanceOf

    Can anyone tell me what's the command in c#
    that is equivalent to the instanceOf in java?

    thanks


  • AlexS

    #2
    Re: instanceOf

    Check GetType and TypeOf

    x instanceOf y

    will be

    x.GetType()==y. GetType();
    or
    TypeOf(x)==Type Of(y);

    HTH
    Alex

    "rua17" <rua17@hotmail. com> wrote in message
    news:O8mMnmiqDH A.2188@TK2MSFTN GP09.phx.gbl...[color=blue]
    > Can anyone tell me what's the command in c#
    > that is equivalent to the instanceOf in java?
    >
    > thanks
    >
    >[/color]


    Comment

    • Mattias Sjögren

      #3
      Re: instanceOf

      >Can anyone tell me what's the command in c#[color=blue]
      >that is equivalent to the instanceOf in java?[/color]

      The 'is' operator

      if ( obj is SomeType )



      Mattias

      --
      Mattias Sjögren [MVP] mattias @ mvps.org

      Please reply only to the newsgroup.

      Comment

      • Jeff Louie

        #4
        Re: instanceOf

        If you are coming from Java this may help:

        Latest news coverage, email, free stock quotes, live scores and video are just the beginning. Discover more every day at Yahoo!


        Chapter 5 "C++ and Java Gumption Traps" 

        Regards,
        Jeff

        *** Sent via Developersdex http://www.developersdex.com ***
        Don't just participate in USENET...get rewarded for it!

        Comment

        • Jon Skeet [C# MVP]

          #5
          Re: instanceOf

          AlexS <salexru2000NO@ SPAMsympaticoPL EASE.ca> wrote:[color=blue]
          > Check GetType and TypeOf
          >
          > x instanceOf y
          >
          > will be
          >
          > x.GetType()==y. GetType();
          > or
          > TypeOf(x)==Type Of(y);[/color]

          No it's not. For instance:

          FileStream fs = new FileStream (...);

          (fs instanceof Stream) should be true, but that won't work with the
          above.

          The equivalent C# operator to Java's "instanceof " operator is "is".

          --
          Jon Skeet - <skeet@pobox.co m>
          Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

          If replying to the group, please do not mail me too

          Comment

          • rua17

            #6
            Re: instanceOf

            thanks

            "AlexS" <salexru2000NO@ SPAMsympaticoPL EASE.ca> wrote in message
            news:uT2#70iqDH A.1408@TK2MSFTN GP11.phx.gbl...[color=blue]
            > Check GetType and TypeOf
            >
            > x instanceOf y
            >
            > will be
            >
            > x.GetType()==y. GetType();
            > or
            > TypeOf(x)==Type Of(y);
            >
            > HTH
            > Alex
            >
            > "rua17" <rua17@hotmail. com> wrote in message
            > news:O8mMnmiqDH A.2188@TK2MSFTN GP09.phx.gbl...[color=green]
            > > Can anyone tell me what's the command in c#
            > > that is equivalent to the instanceOf in java?
            > >
            > > thanks
            > >
            > >[/color]
            >
            >[/color]


            Comment

            Working...