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 1062845
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T18:41:31+00:00 2026-05-16T18:41:31+00:00

MSDN categorizes var under Types . variables that are declared at method scope can

  • 0

MSDN categorizes var under Types.

variables that are declared at method
scope can have an implicit type var

what does ‘implicit type var’ mean in this context?

Strictly said, if I have it to explain to fellow programmers.

Can I say; var is a Type, or do I have to say; var is a keyword that instructs the compiler to determine the type itself.

note: this is not meant to start a discussion about var, nor to learn the use of var. For once and for all I want to know excactly how to describe it and msdn is a bit confusing, that’s it.

  • 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-16T18:41:32+00:00Added an answer on May 16, 2026 at 6:41 pm

    var is a contextual keyword – along with yield, add and get for example.

    In other words, you can use it as an identifer without prefixing it with @, but it still has a special meaning to the compiler in some places (i.e. where a type name is expected for a local variable declaration).

    Using var to declare a local variable asks the compiler to infer the type of the variable based on the expression on the right hand side. For example:

    var list = new List<string>();
    var anon = new { Foo = "bar" };
    

    The type of list is List<string>; the type of anon is an anonymous type, also introduced in C# 3. Part of the reason for introducing var in C# 3 was to allow for strongly typed variables using anonymous types – the variable still has the appropriate compile-time type, even though you couldn’t explicitly state that type.

    There are a few cases where var doesn’t work, however, if the compiler doesn’t have enough information:

    var cantUseNull = null;
    var cantUseLambda = x => x.Length;
    

    There are others too. In each case you could just cast the expression on the right-hand side, so that the compiler knew what to use – but in that case you might as well just declare the variable explicitly instead.

    <plug>
    You can read more about this in C# in Depth. Fortunately, the chapter covering this is still available for free from the first edition page (you want chapter 8). I can’t remember how much I’ve changed this chapter in the second edition…
    </plug>

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

Sidebar

Related Questions

MSDN docs say that only value types need boxing, but this does not apply
From MSDN doc : A delegate is a type that safely encapsulates a method,
MSDN does not list a WPF .exe as a supported type of application for
MSDN said that BlockingCollection.Take call blocks if there is no elements in it. Does
MSDN says : The default implementation of the GetHashCode method does not guarantee unique
MSDN tells me that handles to windows (HWND) can be shared between 32- and
MSDN docs state An expression is a fragment of code that can be evaluated
MSDN defines System.Predicate this way : Represents the method that defines a set of
MSDN points out that mutating access to the .NET Dictionary<K,V> type is not thread
MSDN states that String.Intern retrieves the system's reference to the specified String and String.IsInterned

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.