411 REFERENCE · Wikibooks
C Sharp Programming/Keywords/is
Reference material by Wikibooks contributors. This retains its source identity and is not 411 news reporting.
Keywords is
__TOC__
The is keyword compares an object to a type, and if they're the same or of the same "kind" (the object inherits the type), returns true true. The keyword is therefore used to check for type compatibility, usually before casting (converting) a source type to a destination type in order to ensure that won't cause a type-cast exception to be thrown. Using is on a null null variable always returns false false.
This code snippet shows a sample usage:
System.IO.StreamReader reader = new StreamReader("readme.txt");
bool b = reader is System.IO.TextReader;
// b is now set to true, because StreamReader inherits TextReader