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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T03:42:09+00:00 2026-06-16T03:42:09+00:00

I have a problem… I am trying to put into a list of String

  • 0

I have a problem…
I am trying to put into a list of String dictionary keys values if condition of containsvalue is true:

But, this is not correct 🙁

here is a code:

Private listID As New List(Of String)                       ' declaration of list
Private dictionaryID As New Dictionary(Of String, Integer)  ' declaration of dictionary

  'put a keys and values to dictionary
  dictionaryID.Add("first", 1)
  dictionaryID.Add("second", 2)
  dictionaryID.Add("first1", 1)


    If dictionaryID.ContainsValue(1) Then                 ' if value of dictinary is 1
        Dim pair As KeyValuePair(Of String, Integer)
        listID.Clear()
        For Each pair In dictionaryID
            listID.Add(pair.Key)
        Next
    End If

And now, list must have two elements… -> “first” and “first1”

Can you help me?
Thank you very much!

  • 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-16T03:42:10+00:00Added an answer on June 16, 2026 at 3:42 am

    You are looping through the whole dictionary and add all the elements to the list. You should put an if statement in the For Each or use a LINQ query like this:

    If listID IsNot Nothing Then
        listID.Clear()
    End If
    listID = (From kp As KeyValuePair(Of String, Integer) In dictionaryID
              Where kp.Value = 1
              Select kp.Key).ToList()
    

    Using an if statement:

    listID.Clear()
    For Each pair As KeyValuePair(Of String, Integer) In dictionaryID
        If pair.Value = 1 Then
            listID.Add(pair.Key)
        End If
    Next
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have problem while loading data into html select when users press or click
I have problem SIMILAR to preventing form data reposting, but not quite the same
I have problem with sending objects via TCPClient. At first, I serialize them into
I have problem with encoding data in Oracle database. I want to xor string
I have problem with my own Subversion repository. It worked yesterday. But I received
I have problem dealing with EditItemTemplate. What I am trying to do is to
I have problem with infinite loop in Grails app when rejectIfNoRule = true I
I have problem with spacing between images. I've tried everything but in firefox /
I have problem converting String^ containing 8 bytes as characters (as ascii) to double.
we have problem with slow insert statement using 40 bind variables as columns values.

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.