C#'s 'is' equivalent in D

Just Dave abcdef at 1234.com
Thu Oct 10 15:47:58 UTC 2019


In C# you can do something like:


     if (obj is Person)
     {
         var person = obj as Person;
         // do stuff with person...
     }

where you can check the type of an object prior to casting. Does 
D have a similar mechanism? It's so widely useful in the C# realm 
that they even added syntactic sugar to allow:

     if (obj is Person person)
     {
         // do stuff with person...
     }

I would presume since D has reference objects there must exist 
some mechanism for this...


More information about the Digitalmars-d-learn mailing list