0
我明白,通過引用「複製」列表,數組,對象等類型。然而,我的自然和普通的打算是在這個上下文中有一個「副本」,我故意使用ReadOnly而不是讀/寫屬性。在下面的示例中,ReadOnly'Extensions'屬性通過'm_extensions'引用更改進行更改。無論如何,我認爲這種行爲是不正確的,我不得不做額外的工作來防止覆蓋ReadOnly屬性。是否有任何內置關鍵字用於'm_extensions'值保護?ReadOnly屬性獲取「無意」更改
Public Classs A
' more properties and methods here...
Private m_extensions() As String = {"*.abc", "*.def"}
Public ReadOnly Property Extensions() As String()
Get
Return m_extensions
End Get
End Property
End Class
Public Classs B
' more stuff here...
Private Function BuildFilter() As String
Dim l() As String = A.Extensions
Dim s As String = String.Empty
For m As Integer = 0 To l.Length - 1
Select Case l(m).ToLower
Case "*.*" : s = "All Files"
Case "*.abc" : s = "ABC File"
Case "*.def" : s = "DEF File"
Case Else : s = "XYZ File " + m.ToString
End Select
l(m) = String.Format("{1} ({0})|{0}", l(m), s)
Next
Return String.Join("|", l)
End Function
End Class
感謝Szymon,但我仍然不知道爲什麼有一個「假」只讀標籤,如果50%的病例是不是隻讀可言;) –
嗯,這保證了參考不會受到影響。 – Szymon