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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T10:12:30+00:00 2026-05-18T10:12:30+00:00

I have a dictionary of projects and if I select a project then I

  • 0

I have a dictionary of projects and if I select a project then I will give an option previous and next. I have added a code example but I hope there is a better / faster way to do this e.g. for 500 projects.

Is there maybe a LINQ option or something?

I have checked Enumerator but it only has a moveNext method and can’t set the current.

Quick example:

projects is a Dictionary.

project is a KeyValuePair that exists in the Dictionary.

var match = false;
var save = new KeyValuePair<ExtendedProjectLightPlan, Page>();
var before = new KeyValuePair<ExtendedProjectLightPlan, Page>();
var after = new KeyValuePair<ExtendedProjectLightPlan, Page>();
foreach (var p in projects)
{
    before = save;
    save = p;

    if (match)
    {
        after = p;
        break;
    }

    if (p.Key.Id == project.Key.Id)
    {
        match = true;
    }                
}
  • 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-18T10:12:31+00:00Added an answer on May 18, 2026 at 10:12 am

    There’s nothing built into LINQ to do this, but you could write your own fairly easily… here’s an implementation which uses Tuple from .NET 4. It will return n-2 items for a sequence which originally has n items – but you could adjust that if necessary.

    public IEnumerable<Tuple<T, T, T>> WithNextAndPrevious<T>
        (this IEnumerable<T> source)
    {
        // Actually yield "the previous two" as well as the current one - this
        // is easier to implement than "previous and next" but they're equivalent
        using (IEnumerator<T> iterator = source.GetEnumerator())
        {
            if (!iterator.MoveNext())
            {
                yield break;
            }
            T lastButOne = iterator.Current;
            if (!iterator.MoveNext())
            {
                yield break;
            }
            T previous = iterator.Current;
            while (iterator.MoveNext())
            {
                T current = iterator.Current;
                yield return Tuple.Create(lastButOne, previous, current);
                lastButOne = previous;
                previous = current;
            }
        }        
    }
    

    Note that as per LukeH’s answer, dictionaries are unordered… but hopefully the above will help you anyway.

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

Sidebar

Related Questions

Resource dictionary 03-11-2010 10:56 AM | I have two different projects. I linked a
We have a smelly code in our project. A lot of values which used
I am preparing a simple dictionary project and I have prepared it to search
I have a C# ASP.NET MVC project but my controllers are written in F#.
In my current iPhone project, I have a created a dictionary that groups the
I have three projects under another project of which each contains one namespace. Now
I want to have some constants in a Django Projects. For example, let's say
Have Dictionary <Int64, byte> that gets used a lot. I mean in a loop
I have dictionary, like Dictionary<string, bool> accValues = new Dictionary<string, bool>() And I want
Does VBA have dictionary structure? Like key<>value array?

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.