Property question

  • Thread starter Thread starter Pedro
  • Start date Start date
P

Pedro

Is it possible to have a property with its GET to public and its SET to
private or friend?

or vice versa
 
This was possible in VB6, but as far as I know not in .Net

But, you can simulate it like this:

Private fStorageField as string

Public Readonly Propery StorageField() As String
Get
Return fStorageField
End Get
End Property

Private, you use fStorageField (which is RW), and public you use
Storagefield (Which is RO)

Or, the other way around:
Private fStorageField as string

Public Writeonly Propery StorageField() As String
Set(ByVal value as string)
fStorageField = value
End Get
End Property

Private, you use fStorageField (which is RW), and public you use
Storagefield (Which is WO)

Instead of private, you can also use Friend.
 
Pedro said:
Is it possible to have a property with its GET to public and its SET to
private or friend?

or vice versa

Yes. Example from MSDN:

public string Name
{
get
{
return name;
}
protected set
{
name = value;
}
}
 
Back
Top