Single statement across multiple lines in VB.NET without the underscore character

后端 未结 8 561
死守一世寂寞
死守一世寂寞 2020-12-09 07:42

Is there a way to have a statement across multiple lines without the underscore character?

It is really annoying in multi-line strings such as SQL statements, and es

8条回答
  •  长情又很酷
    2020-12-09 08:23

    No, the underscore is the only continuation character. Personally I prefer the occasional use of a continuation character to being forced to use it always as in C#, but apart from the comments issue (which I'd agree is sometimes annoying), getting things to line up is not an issue.

    With VS2008 at any rate, just select the second and following lines, hit the tab key several times, and it moves the whole lot across.

    If it goes a tiny bit too far, you can delete the excess space a character at a time. It's a little fiddly, but it stays put once it's saved.

    On the rare cases where this isn't good enough, I sometimes use the following technique to get it all to line up:

    dim results as String = ""
    results += "from a in articles "
    results += "where a.articleID = 4 " 'and now you can add comments
    results += "select a.articleName"
    

    It's not perfect, and I know those that prefer C# will be tut-tutting, but there it is. It's a style choice, but I still prefer it to endless semi-colons.

    Now I'm just waiting for someone to tell me I should have used a StringBuilder ;-)

提交回复
热议问题