1

I'm working on an ASP .NET MVC application, and i'm the inexperienced guy on a team of 3. One of my colleagues, the most experienced guy on the team, is constantly using var when defining a variable, although the functions that he uses to load the variable return a specific type(int, string and so on), is this a good practice?

I confronted him with this question but the answer he gave me was "i don't know search for it...", the experienced guy answer, you know...

So, is this a good practice?

Thank you!

  • 1
    I believe this is [well covered here](http://stackoverflow.com/questions/41479/use-of-var-keyword-in-c-sharp) – StuartLC Apr 06 '15 at 09:05
  • Agreed, so closing. It's a matter of opinion anyway. Personally, I used to dislike it in most cases, but grew to like it. –  Apr 06 '15 at 09:07
  • The question linked, is quite different, this question is questioning if it's good practise. – jamierocks Apr 06 '15 at 09:08
  • 1
    This is addressed by by the [Microsoft C# Coding Conventions](https://msdn.microsoft.com/en-us/library/ff926074.aspx) - see the section on *Implicitly Typed Local Variables*. – Matthew Watson Apr 06 '15 at 09:08
  • @jamierocks That's exactly what that other question asks too: not when it's valid, but when it's appropriate. –  Apr 06 '15 at 09:10
  • It's a matter of opinion. For example, if right side of expression returns a complex type like a list or an object i use `var` and if a primitive value is returned then i use explicitly define variable type – Shoaib Shakeel Apr 06 '15 at 09:23

0 Answers0