Keywords As and Is in C#

Asked

Viewed 33 times

0

Well... I was a little confused about the keywords As and Is in C#... I didn’t understand the difference between them nor what they are for... I believe that it is not so difficult to find a explanation on the Internet, but I prefer to ask here, because the sites didn’t go far into this subject...

  • 1

    As I have guided before it would be interesting to research before asking. Almost everything you want to know has already been answered by experienced users on the site and have had the answers rated as good.

1 answer

1


"is" and "as" are keywords used to convert data types. "is": checks whether an object is compatible with a data type and returns true or false. Ex: if(obj is Product) {}. "as" tries to convert an object to a specific type. If the conversion fails it returns null.

To help better understand the difference in this link has a good explanation with examples of codes. http://www.macoratti.net/17/11/c_isas1.htm

Browser other questions tagged

You are not signed in. Login or sign up in order to post.