Operators: as

Used to cast without triggering an exception. More efficient than using the ‘is’ operator as the cast value is returned if the operation is successful while the ‘is’ operator only returns a bool to denote success or failure.

Example:

              Car c = lotus as Car;
              If(c != null)
                            System.Console.WriteLine(“Cast worked”);

 


Discover more from

Subscribe to get the latest posts sent to your email.

Leave a comment

Trending