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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T12:03:54+00:00 2026-05-11T12:03:54+00:00

While analyzing some ASP.NET MVC projects I got to see anonymous types scattered all

  • 0

While analyzing some ASP.NET MVC projects I got to see anonymous types scattered all over.

HTML helpers have them:

<%=Html.TextBox('view.Address', 'address', new { Class = 'text_field' })%> 

A lot of the return types for actions have them:

JsonNetResult jsonNetResult = new JsonNetResult {   Formatting = Formatting.Indented,   Data = new {Something= “”} } 

I know this came from LINQ:

from p in context.Data select new { p.Name, p.Age }; 

Are these really the correct way to accomplish things now outside of LINQ? Do they hurt code reusability and readability?

  • 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. 2026-05-11T12:03:55+00:00Added an answer on May 11, 2026 at 12:03 pm

    IMHO, the biggest problems with anonymous types stem from the inability to name their type. That is, it’s not possible to expilictly specify the type of an anonymous type as an expression in code. This really makes in awkward to do things like create a generic List.

    var list = New List<No way to specify an Ananymous type>(); 

    Usually you have to resort to a helper method.

    public List<T> CreateList<T>(T notUsed) {   return new List<T>(); } var list = CreateList(new { .Class = 'foo' }); 

    This also has a larger impact in that you can’t use an anonymous type as a return type, makes casting extremely awkward (need a helper method), etc …

    But these are not the operations that Anonymous Types were designed for. In many ways they are designed to used within a particular defined function and it’s subsequently created lambda expressions. Not as a data communication type between to full fledged functions. This is certainly a limitation in the design and at times drives me batty. But overall I find them to be a very useful construct in the language.

    Many parts of LINQ would not be possible without them in some form.

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

Sidebar

Related Questions

While analyzing some approaches to making our web app easier to deploy on our
While Ctrl X works fine in vim under windows, Ctrl A selects all (duh).
I'm analyzing the different behaviors between the JTA (Java Transactions API) and the .NET
Is it possible to exclude a complete namespace from all FxCop analysis while still
While testing and analyzing code of Bluetooth Chat, I have questions about my own
While scouring the net for an answer to my problem I have seen multiple
While the C# spec does include a pre-processor and basic directives (#define, #if, etc),
While going through university and from following the development of SO, I've heard a
While I've seen rare cases where private inheritance was needed, I've never encountered a
While setting up CruiseControl, I added a buildpublisher block to the publisher tasks: <buildpublisher>

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.