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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T02:41:48+00:00 2026-05-14T02:41:48+00:00

Scenario Having already read a post on this on the same site, which didn’t

  • 0

Scenario

Having already read a post on this on the same site, which didn’t work, I’m feeling a bit stumped but I’m sure I’ve done this before.

I have a Dictionary.
I want to take the first 200 values from the Dictionary.

CODE

  Dictionary<int,SomeObject> oldDict = new Dictionary<int,SomeObject>();
  //oldDict gets populated somewhere else.
  Dictionary<int,SomeObject> newDict = new Dictionary<int,SomeObject>();
  newDict = oldDict.Take(200).ToDictionary();

OBVIOUSLY, the take returns an IENumerable, so you have to run ToDictionary() to convert it back to a dictionary of the same type. HOWEVER, it just doesn’t work, it wants some random key selector thing – or something? I have even tried just casting it but to no avail.
Any ideas?

  • 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-14T02:41:48+00:00Added an answer on May 14, 2026 at 2:41 am

    Try this:

    newDict = oldDict.Take(200).ToDictionary(x => x.Key, x => x.Value);
    

    Basically a dictionary allows you to iterate over key/value pairs; when you want to convert back to a dictionary, you have to say what to use as the key and what to use as the value.

    However, I would question your code’s correctness – because a dictionary doesn’t have the concept of “the first 200 values”. Don’t rely on the ordering within a dictionary. This will basically give you some effectively-arbitrary 200 entries from within the dictionary.

    What are you trying to do? What’s your idea of the “first” 200 entries?

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

Sidebar

Related Questions

I am having a scenario, in which i have multiple delegates attached to the
How would you test this scenario? I've just started looking into NHibernate and having
I have a scenario for which I am searching a solution. I already have
Imagine having the following scenario: You need to create a system where the Back
I'm having trouble handling the scenario whereby an event is being raised to a
Having some trouble with what should be a very simple scenario. For example purposes,
Scenarion: I am having a web application which is going to use SqlServerReport(SSRS) sitting
I am having some speed issue with my datatables. In this particular case I
I've been having this issue for a while now and was never really able
I'm building an iOS app, which provides a service which our website already provides.

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.