Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 784081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T20:39:15+00:00 2026-05-14T20:39:15+00:00

How does Visual Studio/intellisense know what to do with a variable declared as var

  • 0

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 usings at all?!)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T20:39:16+00:00Added an answer on May 14, 2026 at 8:39 pm

    Your example with a constructor won’t work, but a slightly more involved situation will. For example, suppose you have three types:

    • class Foo in namespace N1
    • class Bar in namespace N2
    • class Baz in namespace N3

    Now suppose Bar has a method which returns an instance of Foo:

    public static Foo GetFoo() { ... }
    

    Here, Bar.cs would need a using directive for N1, unless it specified the name in full.

    Now suppose that we have this code in Baz:

    using N2;
    ...
    var foo = Bar.GetFoo();
    

    That will compile, but

    using N2;
    ...
    Foo foo = Bar.GetFoo();
    

    won’t. The reason is that using directives are only there so that the compiler knows what the name “Foo” means – what its fully qualified name is. In the first snippet, Bar.GetFoo() is effectively declared to return N1.Foo, so the compiler is fine. In the second snippet, the compiler first sees “Foo” and doesn’t know anything about N1, so doesn’t know how to look it up.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

IntelliSense does not work in Visual Studio 2010 if you are inside of a
Hey does anyone know if theres a way in Visual Studio to filter the
I'm using Visual Studio 2008 and I'm used to C# where when Intellisense pops
Does Visual Studio Tools for Office require Office to be installed in order to
Does Visual Studio .NET 2008 come with UISpy? I ask this for for the
Does Visual Studio / Resharper support this? By refactor copy I mean to be
How does visual studio link files to their corresponding designer.cs files? I have a
Which .PDB file does Visual Studio use if you use the attach to process
I'm wondering why does Visual Studio code analysis give a warning with this little
With Visual Studio 2010 right around the corner, what does Visual Studio 2008 Professional

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.