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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T11:27:01+00:00 2026-05-11T11:27:01+00:00

I’m working on a problem in C# 2.0/.NET 2.0 where I have a Sortedlist

  • 0

I’m working on a problem in C# 2.0/.NET 2.0 where I have a Sortedlist and want to search all the ‘values’ (not the ‘keys’) of this SortedList for a certain substring and count up how many occurrences there are.

This is what I’m trying to do:

{    Sortedlist<string,string> mySortedList;    // some code that instantiates mySortedList and populates it with data    List<string> myValues = mySortedList.Values;  // <== does not work    int namesFound = myValues.FindAll(ByName(someName)).Count; } 

Naturally, this doesn’t work because mySortedList.Values returns an IList, while ‘myValues’ is a List. I tried ‘casting’ the IList so that it would be accepted by myValues, but it doesn’t seem to work.

Of course, I can loop over mySortedList.Values in a ‘foreach’ loop, but I don’t really want to do this.

Anyone have any suggestions?

EDIT-1: Ok, well it looks like there isn’t a native way to do this easily. I had assumed that I was just missing something, but apparently I’m not. So I guess I’m just going to do a ‘foreach’ over the IList.

Thanks for the feedback everyone! I voted everyone up 1 because I thought all the feedback was good. Thanks again! 🙂

EDIT-2: Looks like CMS has the answer I was looking for. The only caveat with this (as Qwertie pointed out) is that there is a potential performance penalty since it involves copying all the values to another List and then searching that list start-to-finish. So for short lists, this answer is effective. Longer lists? well that’s up to you to decide…

  • 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. 2026-05-11T11:27:01+00:00Added an answer on May 11, 2026 at 11:27 am

    Since the IList Interface implements IEnumerable, you can actually get a List<T> of values using the List<T> (IEnumerable) Constructor:

    List<string> myValues = new List<string>(mySortedList.Values); 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 271k
  • Answers 271k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer little fix to drupal way: function InMODULE_or_InTHEME_get_current_node() { if ((arg(0)… May 13, 2026 at 1:39 pm
  • Editorial Team
    Editorial Team added an answer When the page loads, include a Javascript variable to indicate… May 13, 2026 at 1:38 pm
  • Editorial Team
    Editorial Team added an answer You should read this first. In summary, you release only… May 13, 2026 at 1:38 pm

Related Questions

I want use html5's new tag to play a wav file (currently only supported
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I've got a string that has curly quotes in it. I'd like to replace
In order to apply a triggered animation to all ToolTip s in my app,

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.