Users Pricing

forum

Home Forums How can var know of an undefined type? – MindStick

How can var know of an undefined type?

Royce Roy 2555 03 Feb 2014

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?


1 Answers

Markdown for AI

A clean, structured version of this page for AI assistants and LLMs.

Open .md