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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T19:52:59+00:00 2026-05-23T19:52:59+00:00

I recently came to realize that you shouldn’t make any assumptions on the implementation

  • 0

I recently came to realize that you shouldn’t make any assumptions on the implementation of an IEnumerable (for example that you can’t assume that when you make changes to one of the objects that came from the IEnumerable during a foreach loop, that after the loop (or even after each iteration) the changed object can be found in the IEnumerable.

So after re-examining my assumptions about IEnumerable, I came to the conclusion that in fact the only thing you can know for sure is that it allows you to traverse all the elements of a collection, where a collection (not ICollection per se) can be anything.

Another assumption that I think that I cannot make is that the order of the underlying collection is something specific. Theoretically you could get the items in a different order everytime you loop over them I’d say.

Now to return to my original question, taking the above into account, First() and Last() could return different items every time (theoretically looking at what an IEnumerable is)?

Exra info:
Of course usually this will be fine because the IEnumerable is implemented by something that is ordered. But what if the IEnumerable makes calls to a webservice to get its elements.

Background info:
I was thinking about this because I wanted to do something specific for the first and last element in a foreach loop. So I checked if(currentElement == Enumerable.Last())

  • 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-23T19:52:59+00:00Added an answer on May 23, 2026 at 7:52 pm

    First() gets an enumerator and return first value that it founds. Last() most often iterates through the whole collection and returns element one before reaching the end of enumeration. And right, that’s all you know for sure. Specifically, collection can be infinite and then Last() will never return.

    There is very helpful series of articles about LINQ operators by Jon Skeet – see Edulinq. He describes every single LINQ operator and discuss all the ideas and assumptions in details. It gives very good insight in how all those things really work.

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

Sidebar

Related Questions

I recently came to know that in C++ pure virtual functions can optionally have
I recently came across a CSS pseudo class that can do an effect for
I recently came across a Windows library called AHK that gives me great control
I recently came upon a Microsoft article that touted new defensive enhancements of Windows
I recently came across a html email that contained _label attributes on the <
I recently came across some Java code that simply put some strings into a
Recently I came across a gcc extension that I have found rather useful: __attribute__(cleanup)
I recently came across a server that's sending a Location header (for a redirect)
I recently came across some weird looking class that had three constructors: class Class
I recently came across classes that use a configuration object instead of the usual

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.