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

The Archive Base Latest Questions

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

I have a List<string> myList = new List<string>(); telling me all of the things

  • 0

I have a

List<string> myList = new List<string>();

telling me all of the things I should find in some input data. I’d like to convert this into a

Dictionary<string, bool> myDict = Dictionary<string, bool>();

where the dictionary keys are the same as the list entries, and all the values are false. I’ll then run over the data, and update the dictionary value when I find the elements.

This seems simple, but

Dictionary<string, bool> myDict = myList.ToDictionary<string, bool>(x => false);

doesn’t work because of an error:

Cannot implicitly convert type Dictionary<bool, string> to Dictionary<string, bool>

  • 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-19T03:09:11+00:00Added an answer on June 19, 2026 at 3:09 am

    You want to do something like this:

    var dict = myList.ToDictionary(s => s, s => false);
    

    The overload that you were using will create a Dictionary<bool, string>, with key being bool and value the string values from the list. ( And having bool as key will mean, you can have only two entries 😉

    Also, you rarely need to specify the type parameters like <string, bool> to methods explcitly, as they can be inferred, and you can use var for variables, like done above.

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

Sidebar

Related Questions

I have a function like this: List<float> myList = new List(float); public void numbers(string
I have a List of String like List<String> MyList=new List<String>{A,B}; and a Dictionary<String, Dictionary<String,String>>
I have a list like this Dim emailList as new List(Of String) emailList.Add(one@domain.com) emailList.Add(two@domain.com)
I can't find an answer anywhere... I have a List<string[]> populated like this: ...
Say for example I have a list as follows: List<string> myList = new List<string>();
I have a list: var myList = new List<string> { red, blue, green };
I have a List of String objects that are pipe delimited. something like this:
I have a list of string like: s = [(abc,bcd,cde),(123,3r4,32f)] Now I want to
I have a String List with items like this Root Root/Item1 Root/Item2 Root/Item3/SubItem1 Root/Item3/SubItem2
I have the following: List<IReport> myList = new List<IReport>(); Report myReport = TheirApi.GetReport(); myReport

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.