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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T17:22:29+00:00 2026-05-13T17:22:29+00:00

In LINQ, what does the select new keyword combination do? I haven’t found much

  • 0

In LINQ, what does the select new keyword combination do?

I haven’t found much documentation on this.

Thanks

  • 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-13T17:22:29+00:00Added an answer on May 13, 2026 at 5:22 pm

    By using select new, you can use the data or objects in the set you are working with to create new objects, either typed anonymously or normally.

    1. Using select new to return new anonymously typed objects:

    var records = from person in people
                  select new { person.name, person.id };
    

    This uses the new keyword to create a set of anonymously typed objects. A new object type is simply created by the compiler, with two properties in it. If you look at the object type in the debugger, you’ll see that it has a crazy-looking, auto-generated type name. But you can also use the new keyword just like you’re used to outside of linq:

    2. Using select new to construct “regularly” typed objects:

    var records = from person in people
                  select new CreditRecord(person.creditLimit, person.name);
    

    This example uses the new keyword just like you’re used to – to construct some known type of object via one of its constructors.

    Select is called a transformation (or projection) operator. It allows you to put the data in the set that you are working with through a transformation function, to give you a new object on the other side. In the examples above, we’re simply “transforming” the person object into some other type by choosing only specific properties of the person object, and doing something with them. So the combination of select new ... is really just specifying the new operation as the transformation function of the select statement. That might make more sense with a counter example to the above two:

    3. Using select without new, with no transformation

    Of course you do not need to use select and new together. Take this example:

    var someJohns =  from person in people
                     where person.name == "John"
                     select person;
    

    This gives you back the original object type that was in the set you were working with – no transformation, and no new object creation.

    4. Using select without new, with a transformation

    And finally, a transformation without the new keyword:

    var personFoods = from person in people
                      select person.GetFavoriteFoods();
    

    which gives you back some new type of object, generated from the transformation function and not by directly using the new keyword to construct it.

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

Sidebar

Related Questions

I am new to Linq and trying to get a handle on how to
There are a lot of questions on SO already about Left joins in Linq,
After discussion with colleagues regarding the use of the 'var' keyword in C# 3
I'm trying to figure out why a simple query in LINQ is returning odd
LINQ-newb having trouble using grouping. I'm trying to query an IEnumerable called dosesWithHighestScore. I'm
I'm new in subsonic3, and I'm getting some errors when I try to use
I am getting the following error when I add the linq grouping. Error 5
I am curious on how exactly LINQ (not LINQ to SQL) is performing is
Using the C# compilers query comprehension features, you can write code like: var names

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.