VB.NETをつつく20-プロパティ2-書き込み専用プロパティ。使う場面が思い浮かばない。
Public MustInherit Class Animal
Private m_name As String
Public ReadOnly Property Name() As String
Get
Return m_name
End Get
End Property
Private m_age As Integer
Public Property Age() As Integer
Get
Return Me.m_age
End Get
Set(ByVal value As Integer)
If value > 0 Then
Me.m_age = value
End If
End Set
End Property
Private m_password As String
'これが書き込み専用プロパティ
Public WriteOnly Property Password() As String
Set(ByVal value As String)
Me.m_password = value
End Set
End Property
Public Sub New(ByVal name As String, ByVal age As Integer)
Me.m_name = name
Me.Age = age
End Sub
Public Overridable Sub Talk()
Console.WriteLine("ワタシハ{0}。年は{1}だよ。", _
Me.Name, Me.Age)
End Sub
Public MustOverride Sub Move()
End Class
うーん苦しい・・・苦しいからこれで終わりピヨ。 もしかしたら使うべき局面があるかもしれないから一応覚えておいてね。 じゃあね。