I do not know what gives ReadOnlyin VB. I think the most explicit that you can get is actually less verbose:
public int Id { get; private set; }
In C #, ReadOnlyindicates that the field value is set at the time the object is created and does not change after the constructor completes. You can achieve this through:
private readonly int _id;
public int Id
{
get { return _id; }
}
, (, ) ReadOnly. , , , . , , VB ReadOnly.
, . VB ReadOnly # 1, , :
' Only code inside class employee can change the value of hireDateValue.
Private hireDateValue As Date
' Any code that can access class employee can read property dateHired.
Public ReadOnly Property dateHired() As Date
Get
Return hireDateValue
End Get
End Property
# ReadOnly . , .
, # VB .
source
share