Use the "is" operator to see if an object can be converted into another type in C#

The "is" operator lets you compare determine whether you can convert an object to a type. For example, suppose the Student class inherits from Person, and that a_student and a_person are objects from the obvious classes. Then the following statements return the indicated results.

a_student is Person    ' True.
a_student is Student ' True.
a_person is Person ' True.
a_person is Student ' False.

   

 

What did you think of this article?




Trackbacks
  • No trackbacks exist for this post.
Comments
  • No comments exist for this post.
Leave a comment

Submitted comments are subject to moderation before being displayed.

 Name

 Email (will not be published)

 Website

Your comment is 0 characters limited to 3000 characters.