How do I write private set auto-properties in VB 10?

 ̄綄美尐妖づ 提交于 2019-11-30 23:00:57

问题


in C#:

public string Property { get; private set; }

in VB?

Please vote or/and share your ideas!


回答1:


I don't think that is possible (yet).

See this link on MSDN.
The above article even links to another one about mixed access levels.

I found this on Microsoft Connect, so they are thinking about it (If it will be for VS2010 that's another question).




回答2:


Like this:

Private Thingy As Integer
Property Thing() As Integer
    Get
        Return Thingy
    End Get
    Private Set(ByVal value As Integer)
        Thingy = value
    End Set
End Property

Auto property in VB10

Property PartNo As Integer = 44302

But with a private set still can't be done in vb not even in VB10 see here:

From MSDN (as john said):

Property Definitions That Require Standard Syntax :

  • Specify different accessibility for the Get and Set procedure. For example, you might want to make the Set procedure Private and the Get procedure Public.



回答3:


According to this MSDN article, you can't:

Auto-implemented properties are convenient and support many programming scenarios. However, there are situations in which you cannot use an auto-implemented property and must instead use standard, or expanded, property syntax.

You have to use expanded property-definition syntax if you want to do any one of the following:

[...]

  • Specify different accessibility for the Get and Set procedure. For example, you might want to make the Set procedure Private and the Get procedure Public.


来源:https://stackoverflow.com/questions/968971/how-do-i-write-private-set-auto-properties-in-vb-10

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!