Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VB.NET Public Property on a single line

Is there any way I can put Public Properties on a single line in VB.NET like I can in C#? I get a bunch of errors every time I try to move everything to one line.

C#:

public void Stub{ get { return _stub;} set { _stub = value; } }

VB.NET

Public Property Stub() As String
    Get
        Return _stub
    End Get
    Set(ByVal value As String)
        _stub = value
    End Set
End Property

Thanks

EDIT: I should have clarified, I'm using VB 9.0.

like image 606
Mark B Avatar asked Sep 23 '11 18:09

Mark B


2 Answers

You can use automatically implemented properties in both VB 10 and C#, both of which will be shorter than the C# you've shown:

public string Stub { get; set; }

Public Property Stub As String

For non-trivial properties it sounds like you could get away with putting everything on one line in VB - but because it's that bit more verbose, I suspect you'd end up with a really long line, harming readability...

like image 73
Jon Skeet Avatar answered Sep 26 '22 07:09

Jon Skeet


Yes you can

Public Property Stub() As String : Get : Return _stub : End Get : Set(ByVal value As String) :_stub = value : End Set : End Property

and you can even make it shorter and not at all readable ;-)

Public Property Stub() As String:Get:Return _stub:End Get:Set(ByVal value As String):_stub = value:End Set:End Property
like image 38
chrissie1 Avatar answered Sep 24 '22 07:09

chrissie1