views:

3135

answers:

5

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 vb shorthand.

+15  A: 

I havent seen any, and I would be very ashamed if I missed that out.

I know it will be a feature in next version (vb10) where you can do:

public property FirstName as String

And it will handle it as your short version in C#, I think they call it "Auto Property"

Stefan
A: 

Not yet but auto properties are coming in VB10.

Nathan W
A: 

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

Jon Limjap
A: 

Not sure about VB, but if you're using Visual Studio 2008, you can right click on a member variable and click "Encapsulate Field". This would auto create the property for you and save you some typing. Not the shortcut you were looking for, but a shortcut of sorts at any rate. Again, not sure if that works with VB, but I don't see why a feature like that would only work with one language in the IDE.

Jason Down
+5  A: 

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

But yeah there is not replacement of VB10 type shortcut in VB9

Ali