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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:48:25+00:00 2026-05-28T01:48:25+00:00

I have a class that only uses the keyCollection of a Dictionary<long, object> ,

  • 0

I have a class that only uses the keyCollection of a Dictionary<long, object>, and I would like to pass to other class only the keys.

I know that the dictionary has a theorical O(1) access-by-index (as a HashTable) but if I convert the keyCollection to a List, the access would change to O(n).

How could I pass the keyCollection to my class maintaining the O(1) access?

Edit: I’m using .NET 2.0.

  • 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-28T01:48:26+00:00Added an answer on May 28, 2026 at 1:48 am

    In a comment, you mention that your intent here is .Contains(). In that case, what you are looking for is HashSet<T>, which does exactly that – it just holds keys (no values), and provides fast Contains checks. So; for your Dictionary<long,object> you could do something like:

    var set = new HashSet<long>(dictionary.Keys);
    

    and pass that over. For convenience, HashSet<T> implements ICollection<T> (if you want to scope it to an interface, rather than the concrete type) – this has a Contains too.

    Actually, it may be more efficient to use (which also works on .NET 2.0):

    ICollection<long> = dictionary.Keys;
    

    and pass that; the implementation of Contains(key) on this is O(1), since it is implemented via:

    bool ICollection<TKey>.Contains(TKey item)
    {
        return this.dictionary.ContainsKey(item);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a custom class that uses boost mutexes and locks like this (only
In shared package i have a class that only uses a class from server
I have a class that uses a variety of methods and other classes as
I have a class that only really ever needed by classes in a certain
I have a template class that is only valid for couple of template parameters:
I have a CORE class that pertains only to my specific site, ie, it
I have a class that defines a read-only property that effectively exposes a private
Given: I have an interface. I have only class that implements that interface. Question:
I have these two methods on a class that differ only in one method
I have method in a class that I need to make sure is only

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.