
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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 Questions & Answers
- What is the purpose of ‘as’ operator in C#?
- How to use ‘is’ operator in C#?
- What is the purpose of the `//` operator in python?
- What is the benefit of MySQL ‘IS NULL’ and ‘IS NOT NULL’?
- What is the meaning and usage of ‘=&’ assignment operator in PHP?
- What is the significance of ‘^’ in PHP?
- What is the use of ‘new’ keyword in C#?
- What is the use of ‘Using’ statement in C#?
- What is the use of ‘ALL’, ‘ANY’, ’SOME’, ’IN’ operators with MySQL subquery?
- What is the use of ‘\c’ option while writing MySQL statements?
- What is ‘this’ reference in Java?
- Rearrange an array such that ‘arr[j]’ becomes ‘i’ if ‘arr[i]’ is ‘j’ in C++
- What is the purpose of the StringBuilder class in C#?
- How to use ‘as’ operator in C#?
- Division without using ‘/’ operator in C++ Program
Advertisements