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

  • Home
  • SEARCH
  • 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 8630655
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:06:21+00:00 2026-06-12T09:06:21+00:00

While going through the ASP.NET MVC docs I see this idiom being used alot:

  • 0

While going through the ASP.NET MVC docs I see this idiom being used alot:

new { foo = "bar", baz = "foo" }

Is this a Dictionary literal syntax?
Is it a new class/struct with the type inferred by the called function definition?
If it is how come the vars don’t need a type definition, not even var?

  • 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-06-12T09:06:22+00:00Added an answer on June 12, 2026 at 9:06 am

    This is an anonymous type.

    Anonymous types provide a convenient way to encapsulate a set of
    read-only properties into a single object without having to explicitly
    define a type first. The type name is generated by the compiler and is
    not available at the source code level. The type of each property is
    inferred by the compiler.

    http://msdn.microsoft.com/en-us/library/bb397696.aspx

    • Anonymous types are strongly typed. From the perspective of the common language runtime, an anonymous type is no different from any other reference type.

    • If two or more anonymous types in the same assembly have the same number and type of properties, in the same order, the compiler treats them as the same type. They share the same compiler-generated type information.

    • Anonymous types should not be passed between assemblies or even as return values from methods (possible, but rarely, rarely advisable).

    • Anonymous types are a convenience mechanism, e.g. when working with LINQ, such as the following projection:

    LINQ Example

    var result = myEnumerable.Select( o => new { foo = o.Foo, bar = o.Bar } );
    // "result" is an enumerable of a new anonymous type containing two properties
    

    Other Questions

    Is this a Dictionary literal syntax?

    No, though there are many similarities. ASP .Net MVC uses RouteValueDictionary and anonymous types to represent the same information in many method overloads.

    how come the vars don’t need a type definition, not even var?

    Value types are inferred, though inference is not always possible: http://msdn.microsoft.com/en-us/library/bb531357.aspx (VB version, if someone knows the URL of the c# equivalent please update)

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

Sidebar

Related Questions

I was just going through the new MVC Music Store tutorial at asp.net. One
While going through some tutorials, I have encountered lines such as this: ((IDisposable)foo).Dispose(); Ignore
I just started a new project, and now with ASP.NET MVC being designed in
I'm using the Data Annotation validation extensively in ASP.NET MVC 2. This new feature
While going through the book Scala for the Impatient , I came across this
Yesterday while going through this question, I found a curious case of passing and
While going through parsing a xml doc i have used multiple if-else to parse
While going through one of our own projects, that other developer used rand() to
I am going though the Apress ASP.NET MVC 3 book and trying to ensure
While going through features of .NET framework 4.5, I found that it supports RFC-compliant

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.