473,387 Members | 1,673 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Property question

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..
Nov 19 '05 #1
5 1601
Hello,

"SStory" <NO***************@msn.com> schrieb:
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
--
MVP · VB Classic, VB .NET
http://www.mvps.org/dotnet
Nov 19 '05 #2
I was afraid of that.

"Stephen Muecke" <st*****@senet.com.au> wrote in message
news:#0**************@tk2msftngp13.phx.gbl...
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
"SStory" <NO***************@msn.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
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..


Nov 19 '05 #3
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

"Herfried K. Wagner" <aon.912666908.N.O.S.P.@.M.aon.at> wrote in message
news:O3**************@TK2MSFTNGP12.phx.gbl...
Hello,

"SStory" <NO***************@msn.com> schrieb:
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
--
MVP · VB Classic, VB .NET
http://www.mvps.org/dotnet

Nov 19 '05 #4
Hello,

"SStory" <NO***************@msn.com> schrieb:
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
--
MVP · VB Classic, VB .NET
http://www.mvps.org/dotnet
Nov 19 '05 #5
Hello,

"SStory >" <Sh*********@online.msn.com <remove the 'online.' to send me
mail> schrieb:
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
--
MVP · VB Classic, VB .NET
http://www.mvps.org/dotnet
Nov 19 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: jeffbernstein | last post by:
Greetings. I'm reading "How to think like a computer scientist: Learning with Python" and there's a question regarding string operations. The question is, "Can you think of a property that...
7
by: vh | last post by:
Hi, I'm new to C#. Most examples about properties I found are sth like the following: class A{ private int property; public int Property { get { return property; } set { property = value; } }...
2
by: Edward Diener | last post by:
How does one specify in a component that a property is a pointer to another component ? How is this different from a property that is actually an embedded component ? Finally how is one notified in...
62
by: djake | last post by:
Someone can explain me why to use property get and property set to access a value in a class, insted of access the value directly? What's the usefulness of property statements in VB.NET? Thanks
27
by: Just Me | last post by:
I made a Usercontrol that must have AutoScroll set to true when it is used. So I set it to True in the Load event. However the property still shows in the properties window when the control is...
3
by: Mark Jones | last post by:
I am quite new to ASP and .Net development and I am building a web-based multiple choice exam application. The web page displays the questions using a Repeater control and the answers are nested...
15
by: Sam Kong | last post by:
Hello! I got recently intrigued with JavaScript's prototype-based object-orientation. However, I still don't understand the mechanism clearly. What's the difference between the following...
10
by: Franky | last post by:
I think I misread a post and understood that if I do: System.Windows.Forms.Cursor.Current = Cursors.WaitCursor there is no need to reset the cursor to Default. So I made all the reset...
0
ADezii
by: ADezii | last post by:
The motivation for this Tip was a question asked by one of our Resident Experts, FishVal. The question was: How to Declare Default Method/Property in a Class Module? My response to the question was...
8
by: Hussein B | last post by:
Hey, I noted that Python encourage the usage of: -- obj.prop = data x = obj.prop -- to set/get an object's property value. What if I want to run some logic upon setting/getting a property?...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.