---
title: "How to use the GetType method?"  
description: "GetType is the basis for usingreflection in .NET. It returns a Type object, describing the object it was calledon. It can then be used to extract type"  
author: "Amit Singh"  
published: 2011-02-09  
updated: 2014-09-18  
canonical: https://www.mindstick.com/blog/112/how-to-use-the-gettype-method  
category: "c#"  
tags: ["c#"]  
reading_time: 1 minute  

---

# How to use the GetType method?

GetType is the basis for usingreflection in .NET. It returns a Type object, describing the object it was calledon. It can then be used to [extract](https://www.mindstick.com/forum/12883/how-to-extract-sub-string-between-two-string-pattern-using-javascript-jquery) type member data like [methods](https://www.mindstick.com/articles/13060/runny-nose-remedy-methods-that-work-best) and fieldsthat may subsequently be used for late-bound method invocations. The GetType method is also [useful](https://www.mindstick.com/articles/12694/how-dolomite-mineral-is-useful-in-human-life) if we getan object at [runtime](https://www.mindstick.com/articles/52/creating-timer-at-runtime-in-c-sharp-dot-net) and we do not know what its type is. We can use thereturned Type object to figure out what to do with the object.

how to use the GetType method.

##### Example:

```
class Employee{ }class Class1{   static void Main()   {        object emp1 = new Employee();        Employeeemp2 = new Employee();        Console.WriteLine(emp1.GetType());        Console.WriteLine(emp2.GetType());        Console.ReadLine();    }}
```

\

##### Note:

\

There aretwo [instances](https://answers.mindstick.com/qa/92508/how-can-you-hide-the-sql-server-instances) of the [Employee](https://www.mindstick.com/articles/85431/remote-employee-training-tips-tricks) class created in the Main method. The first isassigned to a [reference](https://www.mindstick.com/forum/774/reference-what-does-this-error-mean-in-php) of type object and the second is assigned to areference of type Employee. When we run, the [program](https://www.mindstick.com/blog/12337/scaling-up-your-mentorship-program) will print “Employee” asthe [result](https://www.mindstick.com/blog/12011/advantages-of-getting-result-oriented-seo-from-an-agency) of the call to GetType. This shows that GetType returns the run-timetype of the object it is called on, rather than the [compile](https://www.mindstick.com/forum/2316/how-to-views-compile-in-mvc)-time reference itis assigned to.

\

##### Output:

Employee

Employee

---

Original Source: https://www.mindstick.com/blog/112/how-to-use-the-gettype-method

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
