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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T06:14:01+00:00 2026-06-14T06:14:01+00:00

Possible Duplicate: Is a readonly field in C# thread safe? A quite simple program

  • 0

Possible Duplicate:
Is a readonly field in C# thread safe?

A quite simple program

private readonly string _data1;
private readonly int _data2;
private readonly MyAnotherClass _data3;

public MyClass(string data1, int data2, MyAnotherClass data3)
{
    _data1 = data1;
    _data2 = data2;
    _data3 = data3;
}

Are _data1, _data2 and _data3 thread safe?

  • 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-14T06:14:02+00:00Added an answer on June 14, 2026 at 6:14 am

    A read-only variable is guaranteed to be initialized before it is accessed. The initial value is assigned during construction of the object, before the object is fully allocated.

    Variable initializers are transformed into assignment statements, and these assignment statements are executed before the invocation of the base class instance constructor. This ordering ensures that all instance fields are initialized by their variable initializers before any statements that have access to that instance are executed.

    Reference: C# Spec, 10.11.3 Constructor execution (emphasis mine)

    Assignment to a readonly field can only occur as part of the field’s declaration or in a constructor in the same class

    Reference: C# Spec, 1.6.5 Fields

    For that reason, the value will be set before it is available to any thread, and will not change, so it is thread safe.

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

Sidebar

Related Questions

Possible Duplicate: Can I change a private readonly field in C# using reflection? I
Possible Duplicate: List<T> readonly with a private set I have a class as: public
Possible Duplicate: What is the difference between const and readonly? i have doubt in
Possible Duplicate: add “readonly” to <input > (jQuery) This is so weird, I hope
Possible Duplicate: What is the difference between const and readonly? are these interchangeable? can
Possible Duplicate: Can’t create handler inside thread that has not called Looper.prepare() inside AsyncTask
Possible Duplicate: What is the difference between const and readonly? So from what I
Possible Duplicate: getting segmentation fault in a small c program Here's my code: char
Possible Duplicate: regex for URL including query string I have a text or message.
Possible Duplicate: thread with multiple parameters How does one thread a sub with two

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.