Property question

S

SStory

I want to define a base class that has a property, "FirstName"

that is public readonly

but can be set by itself and other objects that inherit this baseclass
(protected)

I can't seem to do that.

The docs show ..

Property Firstname
<attributes>Get
End Get
<attributes>Set
End Set
End property

I wanted to
Public Get
and
Protected Set

but this is not allowed.

Any ideas appreciated..
 
H

Herfried K. Wagner

Hello,

SStory said:
I want to define a base class that has a property,
"FirstName"

that is public readonly

but can be set by itself and other objects that inherit this baseclass
(protected)

I can't seem to do that.

The docs show ..

Property Firstname
<attributes>Get
End Get
<attributes>Set
End Set
End property

I wanted to
Public Get
and
Protected Set

\\\
Public Class Foo
Private m_FirstName As String

Public ReadOnly Property FirstName() As String
Get
Return m_FirstName
End Get
End Property

Protected Sub SetFirstName(ByVal Value As String)
m_FirstName = Value
End Sub
End Class
///

Regards,
Herfried K. Wagner
 
S

SStory

I was afraid of that.

Stephen Muecke said:
AFAIK, the only way to work around this is to create 2 methods

Private m_FirstName as String

Public Function GetFirstName as String
Return m_FirstName
End Function

Protected Sub SetFirstName(ByVal firstName as String)
FirstName = firstName
End Sub

Stephen
 
S

SStory

That is unfortunate. But I can deal with it.
Looks like Microsoft would have allowed a public get and a protected set for
such cases.

Thanks,

shane
 
H

Herfried K. Wagner

Hello,

SStory said:
That is unfortunate. But I can deal with it.
Looks like Microsoft would have allowed a public get
and a protected set for such cases.

That's a "FAQ" and a lot of ppl are annoyed about the fact that it's
impossible to define property Get/Set with different modifiers.

;->

Regards,
Herfried K. Wagner
 
H

Herfried K. Wagner

Hello,

"SStory >" <[email protected] <remove the 'online.' to send me
mail said:
Danke. ;

Ich kann Deutch sprechen, aber nicht zehr gut. Since I learned
Spanish my German and Spanish get confused.

Really good. I think it's better than by bad English.

Regards,
Herfried K. Wagner
 

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

Top