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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T19:33:52+00:00 2026-06-05T19:33:52+00:00

For example can I go: string[] keys = new string[items.Count]; items.Keys.CopyTo(keys); Where items is

  • 0

For example can I go:

string[] keys = new string[items.Count];
items.Keys.CopyTo(keys);

Where items is a:

Dictionary<string, MyObject>

instance that could be being modified by another thread? (Its not clear to me if when accessing the Keys property the inner workings of Dictionary iterates the collection – in which case I know it would not be thread safe).

Update: I realise my above example is not thread safe becuase the size of the Dictonary could change between the lines. however what about:

Dictionary<string, MyObject> keys = items.Keys;
string[] copyOfKeys = new string[keys.Count];
keys.Keys.CopyTo(copyOfKeys );
  • 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-05T19:33:53+00:00Added an answer on June 5, 2026 at 7:33 pm

    No, Dictionary is not thread-safe. If you need thread safety and you’re using .NET 4 or higher, you should use a ConcurrentDictionary.

    From MSDN:

    A Dictionary can support multiple readers concurrently,
    as long as the collection is not modified. Even so, enumerating
    through a collection is intrinsically not a thread-safe procedure. In
    the rare case where an enumeration contends with write accesses, the
    collection must be locked during the entire enumeration. To allow the
    collection to be accessed by multiple threads for reading and writing,
    you must implement your own synchronization.

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

Sidebar

Related Questions

How can I count the occurrence of a character in a string? Example String:
In the following example i can create an object dynamically via a string; however,
how can i get for example the integer codeInt=082 from String code='A082' i have
How can I test if a string contains only whitespace? Example strings: " "
how can i get some part of string (in symbols). For example: $string =
How can I remove duplicate characters from a string using Python? For example, let's
I've a string for example like this: Col&acute;gio How can I convert it to:
Can you write preprocessor directives to return you a std::string or char*? For example:
I can read settings like this, for example: final String mytest = System.getString(this.getContentResolver(), System.AIRPLANE_MODE_ON);
How can I create a new map from two maps of maps so that

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.