---
title: "Difference between Object type and Var type"  
description: "Object type:       Object type is able to store any type of value, because object is the base class of all type. Object type Require to type cast obje"  
author: "Vijay Shukla"  
published: 2012-12-04  
updated: 2014-09-18  
canonical: https://www.mindstick.com/blog/398/difference-between-object-type-and-var-type  
category: "asp.net mvc"  
tags: ["asp.net mvc"]  
reading_time: 1 minute  

---

# Difference between Object type and Var type

##### Object type:

Object type is able to store any type of value, because object is the [base class](https://www.mindstick.com/blog/116/base-class-initilization) of all type. Object type Require to type cast object [variable](https://www.mindstick.com/articles/1807/objective-c-data-types-variables-object-creation) to original type before using it. So this assigning to object type and converting to original type [called as](https://www.mindstick.com/forum/471/why-is-white-box-testing-called-as-glass-box-testing) Boxing and Un-Boxing for value type.

I’m giving example using [simple](https://yourviews.mindstick.com/story/1469/5-simple-ways-to-stay-fit-amp-healthy) [C# Console](https://www.mindstick.com/forum/160515/how-to-read-data-from-text-files-in-the-c-sharp-console-application) base [application](https://www.mindstick.com/articles/12824/calculator-application-in-android) because MVC have same syntax for variables.

##### Example:

```
using System; class A{   public static void Main(String []args)   {       Object x=10;       Object y=20;  Console.WriteLine(Convert.ToInt32(x)+Convert.ToInt32(y));   }}
```

##### Var type:

Var type is able to store any type of value but it requires initializing at the time of declaration. Var type no needs to cast because [compiler](https://www.mindstick.com/articles/27/just-in-time-compiler) has all information to perform operation. It's [define](https://yourviews.mindstick.com/audio/1110/lifestyles-choices-that-define-our-lives) only locally([function](https://www.mindstick.com/articles/13001/multi-statement-table-valued-user-defined-function-in-sql-server) level variable) not globally (class level variable).

##### Example:

```
using System; class A{   public static void Main(String []args)   {       var x=10;       var y=20;   Console.WriteLine(x+y);   }}
```

---

Original Source: https://www.mindstick.com/blog/398/difference-between-object-type-and-var-type

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
