Read-Only Properties
It’s not unusual to give a class the capability of exposing data but not of modifying such data. Continuing the example of the Person
class, imagine you want to expose the FirstName
and LastName
properties plus a FullName
property that returns the full name of the person. This property should be marked as read-only because only the FirstName
and LastName
properties should be editable and FullName
is the result of the concatenation of these two properties. You can therefore define a read-only property as follows:
Public Class Person Public Property FirstName As String Public Property LastName As String Public ReadOnly Property FullName As String Get Return Me.FirstName ...
Get Visual Basic 2015 Unleashed now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.