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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T18:04:07+00:00 2026-05-24T18:04:07+00:00

Because an anonymous type is readonly anyway, is would be more efficient if they

  • 0

Because an anonymous type is readonly anyway, is would be more efficient if they implemented them as structs so that linq queries doesn’t need to create tons of temporary objects:

// This doesn't make any sense, it is just for demonstration
var result = thingies
.Select(x=> new {A = 1, B = 2, C = 3});

Btw. I got this idea, when reading this

EDIT:

The greatest thing would be if the compiler would, depending on the size and usage of the variable (must if be passed to lots of methods), decide whether to make if a value type or reference type.

But could the following sentence which I found in the msdn cause problems then:

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.

Since an anonymous object (with its associated type) cannot leave the method which it is defined in we have no problems here, do we?

  • 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-24T18:04:08+00:00Added an answer on May 24, 2026 at 6:04 pm

    The full .NET garbage collector is particularly well-optimized for two cases: large, long-lived objects that last significant amounts of time, and small, short-lived objects that die off quickly. Gen0 collections are practically free given how fast they are (so fast and frequent, in fact, that many profilers don’t even bother showing them or their contents), so there’s little reason to avoid temporaries that will be gone within the scope of the function that created them.

    Anonymous types fit the second case almost perfectly; they’re not meant to outlive the function that creates them (although you can do it with some trickery). Given this model, and given the fact that most value types are relatively expensive to copy around, and given that many LINQ queries involve a long chain of functions that would all require yet another copy, it makes sense to me that the designers chose to make them reference types.

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

Sidebar

Related Questions

I have a DropDownList populated with a SelectList generated from (an anonymous type) that
I would like to expose a function that can take an optional anonymous method
I have anonymous type variable which i am populating like that(i have two variables
I am really missing something with anonymous types, because I can't figure out what
Because of the more tedious way of adding hosts to be monitored in Nagios
Because I am a newbie I am trying to log out any errors that
Because the float data type in PHP is inaccurate, and a FLOAT in MySQL
Because I've made .cpp files and then transferred them into .h files, the only
In C#, an anonymous type can be as follows: method doStuff(){ var myVar =
I am creating an anonymous type and I have conflicting field names. The following

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.