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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:18:23+00:00 2026-05-22T21:18:23+00:00

var res = new int[1000000].Skip(999999).First(); It would be great if this query would just

  • 0
var res = new int[1000000].Skip(999999).First();

It would be great if this query would just use the indexer instead of traversing 999999 entries.

I had a look into the System.Core.dll and noticed that in contrast to Skip(), the Count() extension method is optimized. If the IEnumerable implements ICollection then it just calls the Count property.

  • 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-22T21:18:23+00:00Added an answer on May 22, 2026 at 9:18 pm

    If you look at my answer to a similar question, it appears as though it should be easy to provide a non-naive (i.e. throws proper exceptions) optimization of Skip for any IList:

        public static IEnumerable<T> Skip<T>(this IList<T> source, int count)
        {
            using (var e = source.GetEnumerator())
                while (count < source.Count && e.MoveNext())
                    yield return source[count++];
        }
    

    Of course, your example uses an array. Since arrays don’t throw exceptions during iteration, even doing anything as complicated as my function would be unnecessary. One could thus conclude that MS didn’t optimize it because they didn’t think of it or they didn’t think it was a common enough case to be worth optimizing.

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

Sidebar

Related Questions

Can not parse json using this var res = eval('(' + response + ')');
var http = require('http'); http.createServer(function (req, res) { if (req.url == '/') { req.url
var UI$Contract$ddlForm_change = function() { //'this' is currently the drop down that fires the
Having the following: var categories = new List<double> {10,20,30,40}; // Note the 40 here...
I am currently working on ServiceStack , just very new to it. (Quite interesting;
i am fetching data using following code _.each(cardIds, function(id){ var mdc = new MdlCard({cardId:
code //array store the markers var googleMarker = []; //this function get json object
I have a collection of this object : public Class MyObject() { public int
I am trying to use this simple code in WCF: Client Side: ServiceContractClient proxy
Am new to Asp.Net Programming, Have just started a web project. Am calling a

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.