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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T18:14:36+00:00 2026-05-14T18:14:36+00:00

Why we need the new in the select statement on one of them? var

  • 0

Why we need the new in the select statement on one of them?

var runs = from sampleDataTable in db.SampleData 
           from sampleInfoTable in db.SampleInfo
           where sampleDataTable.SampleInfo.SampleInfoId == sampleInfoTable.SampleInfoId
           select new {sampleDataTable.Timestamp, sampleDataTable.SampleDataId, sampleInfoTable.Lane} ;

and

var runs2 = from sampleDataTable in db.SampleData
            from sampleInfoTable in db.SampleInfo
            where sampleDataTable.SampleInfo.SampleInfoId == sampleInfoTable.SampleInfoId
               && sampleDataTable.Timestamp == timestamp
            select sampleInfoTable.Lane;
  • 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-14T18:14:37+00:00Added an answer on May 14, 2026 at 6:14 pm

    In the first example you want to select three properties but the return type must be IEnumberable<T> for some type T. With select you are only allowed to select one T per item in the collection you are selecting from. So you have to create an object that contains the three properties and select the reference to that object. This is what new does here – it creates an object of an anonymous type containing the three properties that you requested.

    In the second example you only need to select a reference to one thing. The type T
    can be the type of the property so you don’t need to wrap it in an anonymous type. The second example would work with new too, it just isn’t necessary.

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

Sidebar

Related Questions

I need to add a new SELECT statement whose search condition include something like
guys i need to count new private messages and old one from a table
I am new to MSSQL. i need to change the condition in select statement
I am using .NET 3.5 and need to convert the below select new result
I need to select a node if a condition is matched. I'm totally new
I'm very new at this, but I need to create new tables from existing
I need to copy some data from one table to another in Oracle, while
I need to select some values from a table to be updated, and then
We need to display the result of an SQL SELECT statement on a ASP.NET
I am using a LINQ statement that selects from various tables information I need

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.