开发者

Property encapsulation inserting code automatically, but I don't want it there?

I'm making a public property, and it keeps inserting a snippet of code. What is th开发者_Go百科is code for? And how come it doesn't happen to my other public properties?

Specifically the snippet:

Set(value As ObjectName())

Here's the full public property code:

Public Property PropertyName() As ObjectName()
            Get
                Return Me.propertyName
            End Get
            Set(value As ObjectName())
                Me.propertyName = value
            End Set
        End Property

When I try deleting

(value As ObjectName())

It keeps coming back. But my other properties, that snippet of code doesn't automatically generate...


When you have a property, you need a get and set (unless it is readonly).

The get part is for when other code tries to access the value of the property. The set part is for when other code tries to write the value of the property. The (value As ObjectName()) part is simply the definition of parameter expected.

It will generate for your other properties too, if you were to start typing to define them. Visual Studio is decent at leaving existing code alone. If you already have a property definition, it won't add it.

Again, if you have a ReadOnly property, there will be no set method.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜