构建类 [英] Constructing Classes

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

问题描述

我找到了一个关于XML序列化的优秀教程:
http: //addressof.com/blog/articles/E...alization.aspx

当他创建一个类属性时,它看起来像这样:

公共类驱动程序

私有_wave为字符串

公共属性Wave()为字符串

获取

返回_wave

结束获取

设置(ByVal值为字符串)

_wave =值

结束集

结束财产

结束班级


我的问题是,这样做似乎同样有效:

公共类驱动程序

Public Wave As String

结束类


是否有理由使用Property方法?


Matthew

I found an excellent tutorial on XML Serialization:
http://addressof.com/blog/articles/E...alization.aspx

When he creates a class property, it looks like this:
Public Class Drivers
Private _wave As String
Public Property Wave() As String
Get
Return _wave
End Get
Set(ByVal Value As String)
_wave = Value
End Set
End Property
End Class

My question is, it seems to work equally well when done this way:
Public Class Drivers
Public Wave As String
End Class

Is there a reason to use the Property method?

Matthew

推荐答案



属性基本上是Getter / Setter方法。在设计师中,他们将会在组件的属性页面中显示
。在这样的属性背后理论上隐藏

你的实现(_wave)总是更好。您的

类可能在_wave上有其他依赖项。例如,您可能有一个

" _subwave" item,包含_wave的子集。显然,当用户

设置一个新的_wave时,_subwave仍然引用旧的_wave。在这个

的案例中,您的财产设置了方法将能够释放参考。

这只是一个例子。它们非常灵活,并且不会在最基本的形式中增加很多开销。


Matthew <涂************* @ alltel.net>在消息中写道

新闻:%2 **************** @ TK2MSFTNGP09.phx.gbl ...

Properties are basically Getter/Setter methods. In the designer, they will
appear in the property page of a component too. It is always better to hide
your implementation ( _wave) in theory behind a property like this. Your
class may have other depencies on _wave. For example, you may have a
"_subwave" item, which contains a subset of _wave. Obviously, when the user
sets a new _wave, the _subwave is still referencing the old _wave. In this
case, your property "set" method would be able to release the reference.
Thats just one example. They are flexible and don''t add much overhead in
their most basic form.

"Matthew" <tu*************@alltel.net> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
我找到了关于XML序列化的优秀教程:
http://addressof.com /blog/articles/E...alization.aspx

当他创建一个类属性时,它看起来像这样:
公共类驱动程序
私有_wave As字符串
公共属性Wave()为字符串
获取
返回_wave
结束获取
设置(ByVal值为字符串)
_wave = Value
结束集
结束财产
结束课

我的问题是,这样做似乎同样有效:
公共类司机
公开Wave As String
End Class

是否有理由使用Property方法?

Matthew
I found an excellent tutorial on XML Serialization:
http://addressof.com/blog/articles/E...alization.aspx

When he creates a class property, it looks like this:
Public Class Drivers
Private _wave As String
Public Property Wave() As String
Get
Return _wave
End Get
Set(ByVal Value As String)
_wave = Value
End Set
End Property
End Class

My question is, it seems to work equally well when done this way:
Public Class Drivers
Public Wave As String
End Class

Is there a reason to use the Property method?

Matthew



AND。 。 。


此外,它允许您处理输入或在它之前验证它

设置内部变量


-

OHM(Terry Burns)*使用以下内容给我发电子邮件*


Dim ch()如Char =" ufssz / cvsotAhsfbuTpmvujpotXjui /OFU".ToCharArray()

For i As Int32 = 0 to ch.Length - 1

ch(i)= Convert.ToChar(Convert.ToInt16(ch( i)) - 1)

下一页

Process.Start(" mailto:"& New String(ch))

- -

" Robin Tucker" <编号********** @ reallyidont.com>写在

消息新闻:ck ******************* @ news.demon.co.uk ...
AND . . .

In addition, it allows you to process the input or to validate it before it
sets the internal variable

--
OHM ( Terry Burns ) * Use the following to email me *

Dim ch() As Char = "ufssz/cvsotAhsfbuTpmvujpotXjui/OFU".ToCharArray()
For i As Int32 = 0 To ch.Length - 1
ch(i) = Convert.ToChar(Convert.ToInt16(ch(i)) - 1)
Next
Process.Start("mailto:" & New String(ch))
--
"Robin Tucker" <id*************************@reallyidont.com> wrote in
message news:ck*******************@news.demon.co.uk...

属性基本上是Getter / Setter方法。在设计器中,它们也将出现在组件的属性页面中。在理论上隐藏你的实现(_wave)总是更好
这个。您的课程可能对_wave有其他依赖关系。例如,你可能有一个_subwave。 item,包含_wave的子集。显然,当用户设置一个新的_wave时,_subwave仍然引用旧的
_wave。在这种情况下,您的属性设置方法将能够发布参考。这只是一个例子。它们很灵活,不会以最基本的形式添加很多开销。

马修 <涂************* @ alltel.net>在消息中写道
新闻:%2 **************** @ TK2MSFTNGP09.phx.gbl ...

Properties are basically Getter/Setter methods. In the designer, they
will appear in the property page of a component too. It is always better
to hide your implementation ( _wave) in theory behind a property like
this. Your class may have other depencies on _wave. For example, you
may have a "_subwave" item, which contains a subset of _wave. Obviously,
when the user sets a new _wave, the _subwave is still referencing the old
_wave. In this case, your property "set" method would be able to release
the reference. Thats just one example. They are flexible and don''t add
much overhead in their most basic form.

"Matthew" <tu*************@alltel.net> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
我找到了一个很好的教程XML序列化:
http://addressof.com/blog/articles /E...alization.aspx

当他创建一个类属性时,它看起来像这样:
公共类驱动程序
Private _wave As String
公共属性Wave()As String
获取
返回_wave
结束获取
设置(ByVal值为字符串)
_wave = Value
结束集<结束财产
结束课

我的问题是,这样做似乎同样有效:
公共类驱动程序
Public Wave As String <结束班

是否有理由使用Property方法?

Matthew
I found an excellent tutorial on XML Serialization:
http://addressof.com/blog/articles/E...alization.aspx

When he creates a class property, it looks like this:
Public Class Drivers
Private _wave As String
Public Property Wave() As String
Get
Return _wave
End Get
Set(ByVal Value As String)
_wave = Value
End Set
End Property
End Class

My question is, it seems to work equally well when done this way:
Public Class Drivers
Public Wave As String
End Class

Is there a reason to use the Property method?

Matthew




AND。 。 。


在VS2005中,您可以在级别下方设置get / set(互相
独家)的访问修饰符,并且独立于属性访问

modifer。因此,例如,可以将属性get设置为public并将设置

设置为freind等。


-

OHM (Terry Burns)*使用以下内容给我发电子邮件*


Dim ch()As Char =" ufssz / cvsotAhsfbuTpmvujpotXjui / OFU" .ToCharArray()

对于i As Int32 = 0到ch.Length - 1

ch(i)= Convert.ToChar(Convert.ToInt16(ch(i)) - 1)

下一页

Process.Start(" mailto:"& New String(ch))

-

" One Handed Man (OHM - Terry Burns) < news.microsoft.com>在消息中写道

news:eG **************** @ TK2MSFTNGP10.phx.gbl ...
AND . . .

In VS2005, you are able to set access modifiers for get/set ( Mutually
Exclusively ) below the level and independently of the properties access
modifer. So for example, the property get could be set to public and the set
to freind etc.

--
OHM ( Terry Burns ) * Use the following to email me *

Dim ch() As Char = "ufssz/cvsotAhsfbuTpmvujpotXjui/OFU".ToCharArray()
For i As Int32 = 0 To ch.Length - 1
ch(i) = Convert.ToChar(Convert.ToInt16(ch(i)) - 1)
Next
Process.Start("mailto:" & New String(ch))
--
"One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote in message
news:eG****************@TK2MSFTNGP10.phx.gbl...
AND。 。 。

此外,它允许您处理输入或验证它之前
它设置内部变量

-
OHM(特里烧伤)*使用以下内容给我发电子邮件*

Dim ch()As Char =" ufssz / cvsotAhsfbuTpmvujpotXjui / OFU" .ToCharArray()
For i As Int32 = 0 To ch。长度 - 1
ch(i)= Convert.ToChar(Convert.ToInt16(ch(i)) - 1)
下一步
Process.Start(" mailto:"& New字符串(ch))
-

" Robin Tucker" <编号********** @ reallyidont.com>在消息新闻中写道:ck ******************* @ news.demon.co.uk ...
AND . . .

In addition, it allows you to process the input or to validate it before
it sets the internal variable

--
OHM ( Terry Burns ) * Use the following to email me *

Dim ch() As Char = "ufssz/cvsotAhsfbuTpmvujpotXjui/OFU".ToCharArray()
For i As Int32 = 0 To ch.Length - 1
ch(i) = Convert.ToChar(Convert.ToInt16(ch(i)) - 1)
Next
Process.Start("mailto:" & New String(ch))
--
"Robin Tucker" <id*************************@reallyidont.com> wrote in
message news:ck*******************@news.demon.co.uk...

属性基本上是Getter / Setter方法。在设计器中,它们也将出现在组件的属性页面中。在理论上隐藏你的实现(_wave)总是更好
这个。您的课程可能对_wave有其他依赖关系。例如,你可能有一个_subwave。 item,包含_wave的子集。显然,当用户设置一个新的_wave时,_subwave仍然引用旧的
_wave。在这种情况下,您的属性设置方法将能够发布参考。这只是一个例子。它们很灵活,不会以最基本的形式添加很多开销。

马修 <涂************* @ alltel.net>在消息中写道
新闻:%2 **************** @ TK2MSFTNGP09.phx.gbl ...

Properties are basically Getter/Setter methods. In the designer, they
will appear in the property page of a component too. It is always better
to hide your implementation ( _wave) in theory behind a property like
this. Your class may have other depencies on _wave. For example, you
may have a "_subwave" item, which contains a subset of _wave. Obviously,
when the user sets a new _wave, the _subwave is still referencing the old
_wave. In this case, your property "set" method would be able to release
the reference. Thats just one example. They are flexible and don''t add
much overhead in their most basic form.

"Matthew" <tu*************@alltel.net> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
我找到了一个很好的教程XML序列化:
http://addressof.com/blog/articles /E...alization.aspx

当他创建一个类属性时,它看起来像这样:
公共类驱动程序
Private _wave As String
公共属性Wave()As String
获取
返回_wave
结束获取
设置(ByVal值为字符串)
_wave = Value
结束集<结束财产
结束课

我的问题是,这样做似乎同样有效:
公共类驱动程序
Public Wave As String <结束班

是否有理由使用Property方法?

Matthew
I found an excellent tutorial on XML Serialization:
http://addressof.com/blog/articles/E...alization.aspx

When he creates a class property, it looks like this:
Public Class Drivers
Private _wave As String
Public Property Wave() As String
Get
Return _wave
End Get
Set(ByVal Value As String)
_wave = Value
End Set
End Property
End Class

My question is, it seems to work equally well when done this way:
Public Class Drivers
Public Wave As String
End Class

Is there a reason to use the Property method?

Matthew





这篇关于构建类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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