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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T19:29:38+00:00 2026-05-12T19:29:38+00:00

I have no clue what an anonymous type is in C# nor how it

  • 0

I have no clue what an “anonymous type” is in C# nor how it is used. Can somone give me a good description of it and it’s use?

[Note: i really know what it is and how to use it but thought i’d ask for those that don’t]

  • 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-12T19:29:38+00:00Added an answer on May 12, 2026 at 7:29 pm

    An anonymous type is a type generated by the compiler due to an expression such as:

    new { Property1 = x.Value1, Property2 = y.Value2, z.Value3 }
    

    (the last one is like Value3 = z.Value3).

    The name of the anonymous type is “unspeakable” – i.e. you can’t specify it in normal C# – but it’s a perfectly normal type as far as the CLR is concerned. As you can’t write the name, if you want to create a variable of an anonymous type (or a generic type using an anonymous type as the type argument), you need to use an implicitly typed local variable with the var keyword:

    var person = new { Name = "Bill", Address = "..." };
    

    C# anonymous types are immutable (i.e. the properties are read-only) – the generated type has a single constructor which takes values for all the properties as parameters. The property types are inferred from the values.

    Anonymous types override GetHashCode, Equals and ToString in reasonably obvious ways – the default equality comparer for each property type is used for hashing and equality.

    They are typically used in LINQ in the same way that you’d use “SELECT Value1 As Property1, Value2 As Property2, Value3” in SQL.

    Every anonymous type initializer expression which uses the same property names and types in the same order will refer to the same type, so you can write:

    var x = new { Name = "Fred", Age = 10 };
    x = new { Name = "Bill", Age = 15 };
    

    It’s also worth knowing that VB anonymous types are slightly different: by default, they’re mutable. You can make each individual property immutable using the “Key” keyword. Personally I prefer the C# way, but I can see mutability being useful in some situations.

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

Sidebar

Related Questions

I have no clue how i can get an existing object structure based on
Does anyone have any clue why this doesn't work as expected. If i use
i dont have a clue how i should rewrite this jquery so i can
I have very simple situation and really don't have a clue why this isn't
Well this is really simple but I have no clue.. I have a htaccess
I have no clue how to use QRegExp . I am trying to remove
I am new to regex and really don't have a clue. I have a
I have no clue why this is so hard to do but I can
I have a clue about Object Oriented Programming: I need to have a parent
I have no clue of where to start on this. I've never done any

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.