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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:37:57+00:00 2026-06-18T02:37:57+00:00

I was trying to figure out how to write the proper TakeWhile syntax using

  • 0

I was trying to figure out how to write the proper TakeWhile syntax using lambda in the snippet below, so i can get this filtering to work and return the filtered Dictionary. Can anyone here help? Thanks in advance..

List<KeyValuePair<int, int>> myList = myHashList.ToList();
myList.Sort( (x,y) => x.Value.CompareTo(y.Value) );
var temp = myList.TakeWhile(x => x.Value >= keyToFind);
Dictionary<int, int> outDict = temp.ToDictionary(y => y.Key, y => y.Value);

Let me also mention that here, myHashList is a Dictionary (int,int) with n integer values and integer keys. Ok, here the lambda I am using myList.TakeWhile(x => x.Value >= KeyToFind) is executing just once. That is, x during run-time holds only first record and the comparison is done once and temp has 0 records, although after the 2nd line, myList has n records. But at run-time myList is not in context when the lambda comparison is done. But again, when execution comes back to 4th line, myList is back in context but temp has always 0 records. TakeWhile is not working. Do I need to correct the lambda?

  • 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-06-18T02:37:58+00:00Added an answer on June 18, 2026 at 2:37 am

    Ok, adding the answer myself here. It was a silly thing in fact. The lambda should have been (x => keyToFind >= x.Value) instead of the other way round because always my list started from Value 0 sorted in ascending order and thus would never be >= keyToFind (which again should have been ValueToFind instead of keyToFind as i intended to find Value and not Key), so thanks again!

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

Sidebar

Related Questions

I'm trying to figure out the proper way to write this using Razor syntax:
I've been trying to figure out how to write this regular expression. It is
Trying to figure out how I can do this properly. The print_r looks like
I am using NHibernate, and am trying to figure out how to write a
I'm trying to figure out if I can write javascript that is within an
I'm trying to figure out how to write a regex that can detect if
I'm trying to figure out how to write this function: template <typename Bound> Bound::result_type
Trying to figure out how to write a jquery formula that will sum all
I am trying to figure out how well the global memory write accesses of
trying to figure out why this is happening - I have an input text

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.