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;
}
}
 
Right. Sorry about posting C# code in the VB forum.
 
It's possible in VB 2005 again!

And again we saw a feature that was already known in VB6 return to VB.net
:-)


regards

Michel Posseth [MCP]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top