P
Peter Morris
var myObj = new MyClass();
What is the purpose of using "var" instead of "MyClass"?
What is the purpose of using "var" instead of "MyClass"?
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Peter said:var myObj = new MyClass();
What is the purpose of using "var" instead of "MyClass"?
var myObj = new MyClass();
What is the purpose of using "var" instead of "MyClass"?
var myObj = new MyClass();
What is the purpose of using "var" instead of "MyClass"?

This is what made me ask:
http://codebetter.com/blogs/jeffrey.palermo/archive/2008/03/09/
this-is-how-asp-net-mvc-controller-actions-should-be-unit-tested.aspx
In which he has code like
var repository = new FakeRepository();
var mockViewEngine = new MockViewEngine();
var controller = new MainController(repository, mockViewEngine);
Unlike using "var" in LINQ queries I see no benefit here. In fact I see it
resembling my old BASIC days back in the 1980's
var a = 1;
var b = "2";
var c = a + b;
The answer is "12", not 3 or 12. I'll stick with strongly typed variables
unless using LINQ I think![]()

using *explicitly* typed variables. There's a massive difference. I
suspect you may know this, but others may not - I think it's important
to spread the word that "var != Variant"![]()
I know, but I just don't see a *benefit* to using "var" here except that it
is quicker to type, and seeing as I haven't used less than two fingers to
type since I was about 15 it doesn't really benefit me. How I hated typing
lessons at the time!
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.