How does Visual Studio/intellisense know what to do with a variable declared as var
even if you don't include the necessary using
declaration at the top?
For example, I have class MyDomainObject
defined in a different namespace
If I don't declare using TheOtherNameSpace;
in the file the following code won't compile:
private void Foo()
{
MyDomainObject myObj = new MyDomainObject();
// Doesn't know what this class is
}
But if I use var
var myObj = new MyDomainObject();
This will compile, and intellisense knows exactly what I can with it.
So how the heck does it know what the type is without the using
?
(And as an aside, if it knows without the using
, why do we need using
s at all?!)