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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T15:26:24+00:00 2026-05-28T15:26:24+00:00

SortedList<TKey, TValue>.IndexOfKey(key) returns -1 if key is not in the list. Does this mean

  • 0

SortedList<TKey, TValue>.IndexOfKey(key) returns -1 if key is not in the list.

Does this mean I have to implement a binary search myself if I want to find the index of the key in the list that is greater or equal to key? Or is there something out of the box that I overlooked?

I want to get the result in O(log(n)) of course, so please no LINQ iterate and filter magic.

(In general, I’d like to have something like Java’s NavigableMap functionality, i.e. features like efficient iteration over a sorted map/dictionary, but for now, an answer to the above question would suffice, I can “extension-method” my way from there somehow)

  • 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-28T15:26:25+00:00Added an answer on May 28, 2026 at 3:26 pm

    I’m afraid you’re out of luck, there’s nothing built-in.

    If you create a binary search extension method for IList<T> then you could use it against the Keys property. This is a bit annoying, though not too difficult.

    (The convention used by the framework’s built-in binary search methods — Array and List<T> — is to return the bitwise complement of the index of the next element when the element isn’t found.)

    int index = yourSortedList.Keys.YourBinarySearchExtensionMethod(key);
    if (index >= 0)
    {
        // key found
    }
    else
    {
        // key not found
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I find that SortedList<TKey, TValue> SortedDictionary<TKey, TValue> and Dictionary<TKey, TValue> implement the same interfaces.
i have the next list: SortedList<Decimal, KeyValuePair<string,string>> datos; And i need display this in
I guess everything is in the title... I know that Dictionary<TKey,TValue> does keep the
i have a generic sorted list results with key = some filename and value
Is there any real practical difference between a SortedList<TKey,TValue> and a SortedDictionary<TKey,TValue> ? Are
I'm working with .net 3.5, and I have this: SortedList<int, BrainTickTransition> And I want
I am sorting a list based on multiple fields. sortedList.sort {[it.getAuthor(), it.getDate()]} This works
I'm not familiar with delegates and lambdas but at this moment, I have to
Why is there only a SortedList<TKey, TValue> which looks more like a dictionary, but
I have a sorted collection of objects (it can be either SortedList or SortedDictionary,

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.