Type Checking in C#

Type Checking in C#

The purpose of this article is to introduce you to C# type checking. Using typeof, we can determine the type of built-in types such as int, float, etc, and user-defined types such as classes, interfaces, delegates, and structs. int num = 1; Employee emp = new Employee(); Console.WriteLine(typeof(Employee)); Console.WriteLine(typeof(int)); There is no way to pass user-defined type objects and built-in type variables through typeof. int num = 1; Employee emp = new Employee(); Console.WriteLine(typeof(emp)); // throws compile time error Console.WriteLine(typeof(num)); // throws compile time error The typeof function checks the type at compile time. User-defined type objects may be found…
Read More