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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T21:43:43+00:00 2026-05-15T21:43:43+00:00

I need to do currentKey+1. So i would like to find the index of

  • 0

I need to do currentKey+1. So i would like to find the index of the key value and get the next key (or first if at end). How do i find the current index of the key?

I am using a Dictionary<int, classname> and i looked for .Find or IndexOf with Linq to no avail.

  • 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-15T21:43:44+00:00Added an answer on May 15, 2026 at 9:43 pm

    Dictionaries are not sorted, so the Key doesn’t have any index really. See my question here: Accessing a Dictionary.Keys Key through a numeric index

    Use an OrderedDictionary which has an indexer that takes an Int.

    Edit: ‘m not really sure I understand what you want. If you want to iterate through a Dictionary, just use

    foreach(KeyValuePair kvp in yourDict)
    

    If the key is an Int and you want the next, use

    var newkey = oldkey+1;
    if(yourdict.ContainsKey(newkey)){
        var newvalue = yourdict[newkey];
    }
    

    If the ints are not sequential, you can use

    var upperBound = d.Max(kvp => kvp.Key)+1; // to prevent infinite loops
    while(!yourdict.ContainsKey(newkey) && newkey < upperBound) {
        newkey++;
    }
    

    or, alternatively:

    var keys = (from key in yourdict.Keys orderby key select key).ToList();
    // keys is now a list of all keys in ascending order
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently implementing a Japanese dictionary and would like some ideas on how
I would like to change the value of an input field when the form
I would like to find out, in JavaScript, which element currently has focus. I've
I would like to create an App with python, but i need that it
Currently I need to run two queries to get both the total amount of
Problem Statement: I would like to create an offline database to lookup prices/info on
I have just found a nice look that I would like to use for
I have NOT done much of web-developing and I would like to learn about
I am currently in a situation where I need to find out which tables
I would like to know if spammers have the capabilities to download, crawl and

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.