
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
What is the purpose of ‘is’ operator in C#?
The "is" operator in C# checks whether the run-time type of an object is compatible with a given type or not.
The following is the syntax.
expr is type
Here, expr is the expression
type is the name of the type
The following is an example showing the usage of is operator in C#.
Example
using System; class One { } class Two { } public class Demo { public static void Test(object obj) { One x; Two y; if (obj is One) { Console.WriteLine("Class One"); x = (One)obj; } else if (obj is Two { Console.WriteLine("Class Two"); y = (Two)obj; } else { Console.WriteLine("None of the classes!"); } } public static void Main() { One o1 = new One(); Two t1 = new Two(); Test(o1); Test(t1); Test("str"); Console.ReadKey(); } }
- Related Articles
- What is the purpose of the `//` operator in python?
- What is the purpose of ‘as’ operator in C#?
- Explain the purpose of the ‘in’ operator in JavaScript
- What is the purpose of interfaces in java?
- What is the purpose of VOLUME in Dockerfile?
- What is the purpose of System Programs?
- What is the purpose of System Calls?
- What is the purpose of any research?
- What is the purpose of Human Life?
- What is the purpose of Risk Management?
- What is the Main Purpose of Blockchain?
- What is the purpose of the command interpreter?
- What is the purpose of the testng.xml file?
- What is the purpose of the .gitignore file?
- What is the purpose of System class in Java?

Advertisements