Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

Is a readonly field in VB.NET thread safe? For example, see the code below:

Class Customer
  ReadOnly Name As String

  ReadOnly ZIP As Integer = 98112

  Sub New(ByVal Name As String)

    Me.Name = Name

  End Sub
End Class
share|improve this question
    
By field do you mean a variable or a property? –  briddums Jun 8 '12 at 14:02
add comment

1 Answer

up vote 4 down vote accepted

Yes, if nobody can write it, everyone is synced on its value.

Besides, you could make this integer constant (or shared readonly)

share|improve this answer
1  
you are helpful –  Anon Jun 8 '12 at 8:25
    
I would strongly recommend making it constant, as this documents that A) ZIP will not change within the constructor and B) that all customers have the same ZIP. B is achievable without A by making it shared. –  Brian Jun 8 '12 at 17:26
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.