Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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 typeof, GetType or is in C#?
Typeof()
The type takes the Type and returns the Type of the argument.
GetType()
The GetType() method of array class in C# gets the Type of the current instance.
is
The "is" keyword is used to check if an object can be casted to a specific type. The return type of the operation is Boolean.
Example
class Demo {
}
class Program {
static void Main() {
var demo = new Demo();
Console.WriteLine($"typeof { typeof(Demo)}");
Type tp = demo.GetType();
Console.WriteLine($"GetType {tp}");
if (demo is Demo) {
System.Console.WriteLine($"is keyword check true");
}
Console.ReadLine();
}
}
Output
typeof ConsoleApp.Demo GetType ConsoleApp.Demo is keyword check true
Advertisements