为什么writeonly属性不能重载readonly属性? [英] Why can't a writeonly property overload a readonly property?

查看:79
本文介绍了为什么writeonly属性不能重载readonly属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这只是一个愚蠢的问题,但是为什么你不能只用一个只读一个可写的财产?
只读一个?当然编译器可以分辨出哪一个在编译时调用
,这取决于它是一个赋值还是一个get?


我知道那里无论如何都不是很重要,但是直到带有

的属性获取和设置方法的不同范围被带回(正如乔治在上一篇文章中提到的那样
) 具有不同范围的属性,它将具有以下优点:$ b​​ $ b很高兴执行以下操作:


------------ --------------


私有mName为字符串

Public ReadOnly属性名称()为字符串

获取

返回mName

结束获取

结束物业

受保护的朋友WriteOnly物业名称()作为字符串

设置(ByVal值为字符串)

mName =值

结束集

结束财产


--------------------


这样说,它会更好做到这一点(正如乔治和其他许多人所提到的那样) d):


-----------------------------

私有mName为字符串

公共属性名称()为字符串

公共获取

返回mName

结束获取

受保护的朋友集(ByVal值为字符串)

mName =价值

结束集

结束财产

----------------------------

解决方案




在PDC他们展示了新的语法:


私人mName为字符串

公共属性名称()为字符串

获取

返回mName

结束获取

受保护的朋友集(ByVal Value As String)

mName =价值

结束集

结束物业

----- -----------------------


注意:您使用最可允许的修饰符声明属性,然后

将更严格的修饰符应用于Set或Get,例如Private ot

受保护等。


Codemonkey <胡********* @ hotmail.com>在消息中写道

新闻:ee ************** @ TK2MSFTNGP09.phx.gbl ...

只是一个愚蠢的问题,但是为什么你不能用一个只有一个的写入属性
来重载?当然编译器可以告诉编译时调用哪一个
的区别,这取决于它是一个赋值还是一个get?

我知道没有多少指向这个无论如何,但是直到带有Get和Set方法的不同范围的属性被带回来(正如前一篇文章中关于具有不同范围的属性的
George所要求的那样),它将具有
很高兴做到以下几点:

--------------------------

私人mName作为字符串
公共ReadOnly属性名称()为字符串
获取
返回mName
结束获取
结束属性
受保护的朋友WriteOnly属性名称()为字符串
设置(ByVal值为字符串)
mName = Value
结束集
结束属性

------------ --------

说这样做会更好(就像乔治和其他许多人提到的那样):

--- --------------------------
私有mName为String
公共属性名称()为字符串
公共获取
返回mName
结束获取
受保护的朋友集(ByVal值为字符串)
mName = Value <结束设置
结束财产
----------------------------


我可以看到它实际上是如何有用的,这对它的工作是一种耻辱。


我只能假设由于内部设计编译器的方式,这将导致微软的复杂性太多,需要克服b $ b。或者,也许他们根本没想到它?


谁知道!,也许你应该向他们推荐


问候 - OHM#< Codemonkey写道:

只是一个愚蠢的问题,但是为什么你不能用一个只读的超载一个可写的
属性?当然编译器可以告诉编译时调用哪一个的区别,取决于它是一个赋值还是一个get?

我知道没有无论如何都要指出这一点,但是直到具有Get和Set方法的不同范围的属性被带回(如George在前一篇文章中提到的关于具有不同
范围的属性),做以下事情会很不错:

--------------------------

私有mName为字符串
公共ReadOnly属性名称()为字符串
获取
返回mName
结束获取
结束属性
受保护的朋友WriteOnly属性名称()作为字符串
设置(ByVal值为字符串)
mName =值
结束集
结束属性

-------- ------------

说这样做会更好(就像乔治和其他人提到的那样):
-----------------------------
私人mName A. s字符串
公共属性名称()为字符串
公共获取
返回mName
结束获取
受保护的朋友集(ByVal值为字符串)
mName =价值
结束集
结束财产
----------------------------




问候 - OHM# On ********** @ BTInternet.com


新的你是指惠德贝?


问候 - OHM#
<比尔麦卡锡写道:



在PDC,他们展示了新的语法:

私人mName为字符串
公共属性名称()为字符串
获取
返回mName
结束获取
受保护的朋友集(ByVal值为字符串)
mName = Value 结束财产
----------------------------

注意:您使用最可允许的修饰符声明属性,
然后a例如,Set或Get的限制性更强的修饰符,例如私人保护等。


Codemonkey <胡********* @ hotmail.com>在消息中写道
新闻:ee ************** @ TK2MSFTNGP09.phx.gbl ...

只是一个愚蠢的问题,但为什么可以'你只用一个只写一个writeonly
属性吗?当然编译器可以告诉编译时调用哪一个的区别,取决于它是一个赋值还是一个get?

我知道没有无论如何都要指出这一点,但是直到具有Get和Set方法的不同范围的属性被带回(如George在前一篇文章中提到的关于具有不同
范围的属性),做以下事情会很不错:

--------------------------

私有mName为字符串
公共ReadOnly属性名称()为字符串
获取
返回mName
结束获取
结束属性
受保护的朋友WriteOnly属性名称()作为字符串
设置(ByVal值为字符串)
mName =值
结束集
结束属性

-------- ------------

说这样做会更好(就像乔治和其他人提到的那样):
-----------------------------
私人mName A. s字符串
公共属性名称()为字符串
公共获取
返回mName
结束获取
受保护的朋友集(ByVal值为字符串)
mName =价值
结束集
结束财产
----------------------------




问候 - OHM# On ****** ****@BTInternet.com


Just a silly question, but why can''t you overload a writeonly property with
a readonly one? Surely the compiler can tell the difference of which one to
call at compile time, depending on if it is an assignment or a get?

I know there isn''t much point to this anyway, but until Properties with
different scope for Get and Set methods are brought back (as asked by George
in a previous post about "properties with different scope", it would have
been nice to do the following:

--------------------------

Private mName As String
Public ReadOnly Property Name() As String
Get
Return mName
End Get
End Property
Protected Friend WriteOnly Property Name() As String
Set(ByVal Value As String)
mName = Value
End Set
End Property

--------------------

Saying that, it would be nicer to do this (as George and numerous others
mentioned):

-----------------------------
Private mName As String
Public Property Name() As String
Public Get
Return mName
End Get
Protected Friend Set(ByVal Value As String)
mName = Value
End Set
End Property
----------------------------

解决方案

Hi,

At the PDC they showed the new syntax:

Private mName As String
Public Property Name() As String
Get
Return mName
End Get
Protected Friend Set(ByVal Value As String)
mName = Value
End Set
End Property
----------------------------

Note: you declare the property with the most permissible modifier, then
apply the more restrictive modifier to the Set or Get, such as Private ot
Protected etc.


"Codemonkey" <hu*********@hotmail.com> wrote in message
news:ee**************@TK2MSFTNGP09.phx.gbl...

Just a silly question, but why can''t you overload a writeonly property with a readonly one? Surely the compiler can tell the difference of which one to call at compile time, depending on if it is an assignment or a get?

I know there isn''t much point to this anyway, but until Properties with
different scope for Get and Set methods are brought back (as asked by George in a previous post about "properties with different scope", it would have
been nice to do the following:

--------------------------

Private mName As String
Public ReadOnly Property Name() As String
Get
Return mName
End Get
End Property
Protected Friend WriteOnly Property Name() As String
Set(ByVal Value As String)
mName = Value
End Set
End Property

--------------------

Saying that, it would be nicer to do this (as George and numerous others
mentioned):

-----------------------------
Private mName As String
Public Property Name() As String
Public Get
Return mName
End Get
Protected Friend Set(ByVal Value As String)
mName = Value
End Set
End Property
----------------------------



I can see how this could be useful actually and its a shame it doesent work.

I can only assume that due to the way the compiler is designed internally
that this would have caused complications for Microsoft which were too much
to overcome. Alternatively, maybe they simply didnt think of it ?

Who knows!, perhaps you should suggest it to them

Regards - OHM#
Codemonkey wrote:

Just a silly question, but why can''t you overload a writeonly
property with a readonly one? Surely the compiler can tell the
difference of which one to call at compile time, depending on if it
is an assignment or a get?

I know there isn''t much point to this anyway, but until Properties
with different scope for Get and Set methods are brought back (as
asked by George in a previous post about "properties with different
scope", it would have been nice to do the following:

--------------------------

Private mName As String
Public ReadOnly Property Name() As String
Get
Return mName
End Get
End Property
Protected Friend WriteOnly Property Name() As String
Set(ByVal Value As String)
mName = Value
End Set
End Property

--------------------

Saying that, it would be nicer to do this (as George and numerous
others mentioned):

-----------------------------
Private mName As String
Public Property Name() As String
Public Get
Return mName
End Get
Protected Friend Set(ByVal Value As String)
mName = Value
End Set
End Property
----------------------------



Regards - OHM# On**********@BTInternet.com


By new you mean Whidbey ?

regards - OHM#

Bill McCarthy wrote:

Hi,

At the PDC they showed the new syntax:

Private mName As String
Public Property Name() As String
Get
Return mName
End Get
Protected Friend Set(ByVal Value As String)
mName = Value
End Set
End Property
----------------------------

Note: you declare the property with the most permissible modifier,
then apply the more restrictive modifier to the Set or Get, such as
Private ot Protected etc.


"Codemonkey" <hu*********@hotmail.com> wrote in message
news:ee**************@TK2MSFTNGP09.phx.gbl...

Just a silly question, but why can''t you overload a writeonly
property with a readonly one? Surely the compiler can tell the
difference of which one to call at compile time, depending on if it
is an assignment or a get?

I know there isn''t much point to this anyway, but until Properties
with different scope for Get and Set methods are brought back (as
asked by George in a previous post about "properties with different
scope", it would have been nice to do the following:

--------------------------

Private mName As String
Public ReadOnly Property Name() As String
Get
Return mName
End Get
End Property
Protected Friend WriteOnly Property Name() As String
Set(ByVal Value As String)
mName = Value
End Set
End Property

--------------------

Saying that, it would be nicer to do this (as George and numerous
others mentioned):

-----------------------------
Private mName As String
Public Property Name() As String
Public Get
Return mName
End Get
Protected Friend Set(ByVal Value As String)
mName = Value
End Set
End Property
----------------------------



Regards - OHM# On**********@BTInternet.com


这篇关于为什么writeonly属性不能重载readonly属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆