VB.NET 等效于 C# 属性简写?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/460027/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
VB.NET equivalent of C# property shorthand?
提问by Birk
Is there a VB.NET equivalent to the C#:
是否有与 C# 等效的 VB.NET:
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.
但我似乎无法在 Visual Basic 速记上搜索答案。
采纳答案by Stefan
There is no shorthand for Visual Studio 2008 or prior for VB.NET.
Visual Studio 2008 或之前版本的 VB.NET 没有简写。
In Visual Studio 2010 and beyond, you can use the following shorthand:
在 Visual Studio 2010 及更高版本中,您可以使用以下速记:
public property FirstName as String
This will be handled as your short version in C# is - I think they call it "Auto Property"
这将按照您在 C# 中的简短版本进行处理 - 我认为他们称之为“自动属性”
回答by Jon Limjap
Unfortunately, Visual Basic 9 (which ships with .NET 3.5/Visual Studio 2008) does not have automatic properties.
不幸的是,Visual Basic 9(随 .NET 3.5/Visual Studio 2008 一起提供)没有自动属性。
回答by Ali
In Visual Studio 2008, after typing just the keyword Property
, press the Tabkey. It'll paste a template snippet for you which you can fill very quickly.
在 Visual Studio 2008 中,仅键入关键字 后Property
,按Tab键。它会为您粘贴一个模板片段,您可以非常快速地填写。
But yeah, there is not a replacement of a Visual Basic 10-type shortcut in Visual Basic 9.
但是,是的,没有替代 Visual Basic 9 中的 Visual Basic 10 类型的快捷方式。