函数与ReadOnly属性 [英] Function versus ReadOnly Property

查看:75
本文介绍了函数与ReadOnly属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有理由使用:


私有newPropertyValue作为整数

Public ReadOnly属性MyProperty(ByRef MyParam as Integer)As

整数

获取

返回newPropertyValue

结束获取

结束物业

而不是:


将MyValue调整为整数

公共函数MyFunction(ByRef MyParam as Integer)作为整数

返回MyValue

结束功能

解决方案

>是否有任何理由使用:


私有newPropertyValue作为整数
Public ReadOnly属性MyProperty(ByRef MyParam as Integer)为
整数
获取结束获取
结束属性
而不是:

将MyValue调整为整数
公共函数MyFunction(ByRef MyParam as Integer)As Integer
返回MyValue
结束函数




一个实际的原因是ASP不能绑定到一个函数(或至少它

如果不再是这样的话,就不能玩ASP 2.0了。





除了Jim评论之外,我真的不认为这是好形式

有一个属性有参数。


Ken

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


"呃********* *@gmail.com"写道:

有什么理由可以使用:

私有newPropertyValue作为整数
Public ReadOnly属性MyProperty(ByRef MyParam as Integer)As
整数
获取
返回newPropertyValue
结束获取
结束属性

而不是:

将MyValue调整为整数
Public Function MyFunction(ByRef MyParam as Integer)As Integer
返回MyValue
结束函数



你好 er**********@gmail.com


作为一般经验法则,当

时使用属性1.您不需要传递参数(当然除非数据类型是

a集合/列表和参数是项目索引)

2.您不需要进行任何处理


如果条件1或2失败则使用功能。


-Boo
有没有理由可以使用:

私有newPropertyValue作为整数
Public ReadOnly属性MyProperty(ByRef MyParam as Integer)为
整数
获取
返回newPropertyValue
结束获取
结束属性
而不是:

将MyValue作为整数调暗
公共函数MyFunction(ByRef MyParam as Integer )作为整数
返回MyValue
结束函数



Is there any reason to use:

Private newPropertyValue As Integer
Public ReadOnly Property MyProperty(ByRef MyParam as Integer) As
Integer
Get
Return newPropertyValue
End Get
End Property

instead of:

Dim MyValue as Integer
Public Function MyFunction(ByRef MyParam as Integer) As Integer
Return MyValue
End Function

解决方案

> Is there any reason to use:


Private newPropertyValue As Integer
Public ReadOnly Property MyProperty(ByRef MyParam as Integer) As
Integer
Get
Return newPropertyValue
End Get
End Property
instead of:

Dim MyValue as Integer
Public Function MyFunction(ByRef MyParam as Integer) As Integer
Return MyValue
End Function



One practical reason is that ASP can''t bind to a function (or at least it
couldn''t, haven''t played with ASP 2.0 enough if this is no longer the case).


Hi,

In addition to Jim comments I really dont think it is good form to
have a property that has a parameter.

Ken
------------------

"er**********@gmail.com" wrote:

Is there any reason to use:

Private newPropertyValue As Integer
Public ReadOnly Property MyProperty(ByRef MyParam as Integer) As
Integer
Get
Return newPropertyValue
End Get
End Property

instead of:

Dim MyValue as Integer
Public Function MyFunction(ByRef MyParam as Integer) As Integer
Return MyValue
End Function



Hello er**********@gmail.com,

As a general rule of thumb, use a property when
1. You do not need to pass parameters (unless of course the data type is
a collection/list and the parameter is the item index)
2. You do not need to do any processing

If conditions 1 or 2 fail then use a function.

-Boo

Is there any reason to use:

Private newPropertyValue As Integer
Public ReadOnly Property MyProperty(ByRef MyParam as Integer) As
Integer
Get
Return newPropertyValue
End Get
End Property
instead of:

Dim MyValue as Integer
Public Function MyFunction(ByRef MyParam as Integer) As Integer
Return MyValue
End Function



这篇关于函数与ReadOnly属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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