VB.NET equivalent of C# property shorthand?

╄→尐↘猪︶ㄣ 提交于 2019-11-26 12:57:21

问题


Is there a VB.NET equivalent to the C#:

public string FirstName { get; set; }

I know you can do

Public Property name() As String
   Get
      Return _name.ToString
   End Get
   Set(ByVal value As String)
       _name = value
   End Set
End Property

But I can\'t seem to google up an answer on a Visual Basic shorthand.


回答1:


There is no shorthand for Visual Studio 2008 or prior for VB.NET.

In Visual Studio 2010 and beyond, you can use the following shorthand:

public property FirstName as String

This will be handled as your short version in C# is - I think they call it "Auto Property"

See also: Auto-Implemented Properties (Visual Basic)




回答2:


In Visual Studio 2008, after typing just the keyword Property, press the Tab key. It'll paste a template snippet for you which you can fill very quickly.

But yeah, there is not a replacement of a Visual Basic 10-type shortcut in Visual Basic 9.




回答3:


Unfortunately, Visual Basic 9 (which ships with .NET 3.5/Visual Studio 2008) does not have automatic properties.



来源:https://stackoverflow.com/questions/460027/vb-net-equivalent-of-c-sharp-property-shorthand

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