Is there an equivalent to the instanceof operator in Visual J++?

C# has the is operator:

expr is type

Showing Answers 1 - 6 of 6 Answers

sasi4u

  • Sep 29th, 2008
 

EX:
==============
using
System;
 
class ClassA {}
 
public class TestIs
{
   public static void Test (object o)
   {
      ClassA a = null;
 
      if (o is ClassA)
      {
         Console.WriteLine ("o is ClassA");
         a = (ClassA) o;
       }
      else
      {
         Console.WriteLine ("o is not ClassA.");
      }
   }
 
   public static void Main()
   { ClassA cA = new Class1();
      Test (cA);
      Test ("example string");
   }
}

Elean0r

  • May 24th, 2011
 

The C# "is" operator can be used to test whether an object reference ( run-time type) is compatible with a defined type  ( compile type).  The operator returns a Boolean result and is hence most often used within an if statement.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions