![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Getting the type of the current instance in C#
To get the type of the current instance, the code is as follows −
Example
using System; public class Demo { public static void Main(){ string s = "Demo"; Console.WriteLine("String = " +s); Console.WriteLine("String Type = " +s.GetType()); } }
Output
This will produce the following output −
String = Demo String Type = System.String
Example
Let us now see another example −
using System; public class Demo { public static void Main(){ double val1 = 5.5; int val2 = 10; short val3 = 2; Console.WriteLine("Value = " +val1); Console.WriteLine("Value Type = " +val1.GetType()); Console.WriteLine("Value = " +val2); Console.WriteLine("Value Type = " +val2.GetType()); Console.WriteLine("Value = " +val3); Console.WriteLine("Value Type = " +val3.GetType()); } }
Output
This will produce the following output −
Value = 5.5 Value Type = System.Double Value = 10 Value Type = System.Int32 Value = 2 Value Type = System.Int16
Advertisements