C# as Operator

C# Code Snippets as operator


In this code snippet, we will learn how to use the as operator in C#.

The as operator is used to cast objects into different types. It is similar to the is operator. They can both be used to check if an object is of a certain type.

If the conversion is successful the converted object gets returned else a null will be returned.

Let’s have a look at the code below to see how to use the as operator.


[amp-gist id=”f628cfee543f3ed98245d77728a87f47″]

Resulting output:


Leave a Reply

Your email address will not be published. Required fields are marked *

The reCAPTCHA verification period has expired. Please reload the page.
The following GDPR rules must be read and accepted:
This form collects your name, email and content so that we can keep track of the comments placed on the website. For more info check our privacy policy where you will get more info on where, how and why we store your data.

Advertisment ad adsense adlogger