-1

For ex: I am having class name data and am going to create instance for this

var abc =new data()

And data abc =new data() here why we can go for var?

  • Possible duplicate of [What's the point of the var keyword?](http://stackoverflow.com/questions/209199/whats-the-point-of-the-var-keyword) – Jasen Mar 16 '17 at 04:03
  • It _sometimes_ helps with readability and future refactoring. The linked question covers many reasons. – Jasen Mar 16 '17 at 04:10
  • Possible duplicate of [Use of var keyword in C#](http://stackoverflow.com/questions/41479/use-of-var-keyword-in-c-sharp)... – Jeff Mercado Mar 16 '17 at 05:41

1 Answers1

1

Var keyword is an implicit way of defining Data Types. Implicit means indirect way of defining variable types. In simple words by looking the data at the right hands side the left hands side data types is defined by the compiler during the generation of the “IL” code. In the case of class instance, var provides two important uses, such as,

  1. When you have long class names and your code is not readable so by using “Var” keyword the code becomes short and sweet.

  2. When you are using LINQ and anonymous types “Var” keyword reduces your code for creating special classes.

Please click on this link and scroll to the middle of the page, you can find why to use var in case of class instance.

Basanta Matia
  • 1,504
  • 3
  • 15
  • 27