How it works...

The preceding code will not fail nor throw any exceptions. It will just return the null value instead. Our casting test code is going to print the following output to the console:

null
8.802117014997226
null

Using the safe as? casting modifier is a neat alternative to the traditional way. You can use it if you are working with nullable types, that is while working with external libraries that don't provide the null safety. However, if you can benefit from the null safety, it's best to use the standard casting operation.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.222.199.131