How can var know of an undefined type?

Viewed 1743

How can the implicit type variable var know a type that is not defined in the scope (using using)?

Example:

This is ok

public class MyClass
{
    public void MyMethod        
    {
        var list = AStaticClass.GetList();
    }
}

But this is not ok

public class MyClass
{
    public void MyMethod        
    {
        List<string> list = AStaticClass.GetList();
    }
}

In the last code snippet I have to add using System.Collections.Generic; for it to work.

How does this work?

2 Answers
Related