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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T01:02:28+00:00 2026-06-15T01:02:28+00:00

I have the following code: class Program { static void Main(string[] args) { foreach

  • 0

I have the following code:

class Program
{
    static void Main(string[] args)
    {
        foreach (var item in GetEnumerable().Skip(100))
        {
            Console.WriteLine(item);
        }
    }
    static IEnumerable<int> GetEnumerable(int? page = null, int limit = 10)
    {
        var currentPage = page ?? 1;
        while (true)
        {
            Thread.Sleep(1000); // emulates slow retrieval of a bunch of results
            for (int i = limit * (currentPage - 1); i < limit * currentPage; i++)
            {
                yield return i;
            }
            currentPage++;
        }
    }
}

I’d like to be able to use .Skip(n) to efficiently skip results I don’t need. So, for example, if I use Skip(100) and each request retrieves 10 items, the first 10 requests should be skipped entirely.

Is there a pattern I can use to achieve this?

  • 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-15T01:02:29+00:00Added an answer on June 15, 2026 at 1:02 am

    You can create your own IEnumerable<int> type and provide your own implementation of Skip:

    public class PagedEnumerable : IEnumerable<int>
    {
        private readonly int currentPage;
        private readonly int limit;
    
        public PagedEnumerable(int currentPage, int limit)
        {
            this.currentPage = currentPage;
            this.limit = limit;
        }
    
        public PagedEnumerable Skip(int count)
        {
            int pages = count / this.limit;
            return new PagedEnumerable(this.currentPage + pages, this.limit);
        }
    
        public IEnumerator<int> GetEnumerator()
        {
            int pageNo = this.currentPage;
            while (true)
            {
                Thread.Sleep(1000);
                for (int i = this.limit * (pageNo - 1); i < (this.limit * pageNo); i++)
                {
                    yield return i;
                }
                pageNo++;
            }
        }
    
        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
        {
            return this.GetEnumerator();
        }
    }
    

    You can then replace your GetEnumerable with:

    static PagedEnumerable GetEnumerable(int? page = null, int limit = 10)
    {
        var currentPage = page ?? 1;
        return new PagedEnumerable(currentPage, limit);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code: class Program { static void Main(string[] args) { new
i have written the following code class Program { static void Main(string[] args) {
I have the following code: class Program { static void Main(string[] args) { Test
I have the following code: class Program { static void Main(string[] args) { using
Hi I have following test code: class Program { static void Main(string[] args) {
I have the following code Snippet. class Program { static void Main(string[] args) {
I have the following code class Program { static void Main(string[] args) { List<A>
I have the following code: class Program { static void Main(string[] args) { Console.WriteLine(SqrtRoot(0));
I have the following code: class Program { static void Main(string[] args) { string
I have the following code: class Test { public static void main(String[] args) {

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.