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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T09:15:37+00:00 2026-06-05T09:15:37+00:00

A lot of statements (often seen in Linq) use TSource when it isn’t required

  • 0

A lot of statements (often seen in Linq) use TSource when it isn’t required for either compilation or execution. Why would you specify TSource?

Example:

 List<int> list = new List<int>(5) { 0, 1, 2, 0, 3 };

 int x = list.Where<int>(i => i == 0).FirstOrDefault<int>();
 int y = list.Where(i => i == 0).FirstOrDefault();

How do the statements differ?

  • 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-06-05T09:15:39+00:00Added an answer on June 5, 2026 at 9:15 am

    In both of your LINQ statements the TSource type is required.

    It is just explicitly provided in the first statement and implicitly inferred in the second.

    You would specify TSource in circumstances where the compiler cannot infer the type – often when the lambda is nested and very complicated.

    Also, if you wanted the operation to be performed using a supertype of type used in the lamdba. For example, you might specify the Fruit type rather than let it infer Apple if Apple inherits from Fruit.

    Finally, you may choose to specify (or not) the TSource just to make your code more readable – either by explicitly including the type or by removing redundant type repetition.

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

Sidebar

Related Questions

There are a lot of statements where we can use any one of, conditional
Currently we have a lot of web pages that either have SQL statements embedded
I often use print_r($value, true) to dump some variables in log statements, and sometimes
Either this this question isn't asked often (possible), everyone knows how to do it
I've been reading a lot about prepared statements and in everything I've read, no
I have a shell script with a lot of echo statements. I want to
I have a PHP file that contains a lot of if and else statements
I've read a lot about star-schema's, about fact/deminsion tables, select statements to quickly report
I have a file containing a lot of SQL statements, such as: CREATE TABLE
Working with legacy code, I found I got are lot of statements (more than

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.