vb.net – 在Visual Basic .NET中缩进多行IF语句的编码样式

如果你有一个多行IF语句,默认缩进可能有点难以阅读:

If SomeConditionA _
    AndAlso SomeConditionB _
    AndAlso SomeConditionC Then
    DoSomething()
End If

我可以想到一些解决这个问题的方法,例如:

>将第二行和第三行缩进8而不是4个空格,
>根本没有缩进第二和第三行,
>在第三行之后添加一个空行,
> ……

但是我想知道这种情况是否有一些完善甚至官方推荐的编码风格.

解决方法

实际上根据 coding conventions,你应该

Avoid using the explicit line continuation character “_” in favor of
implicit line continuation wherever the language allows it.

所以代码应该看起来像这样:

If SomeconditionA AndAlso
        SomeconditionB AndAlso
        SomeconditionC Then
        DoSomething()
    End If

然后它说:

If Pretty listing (reformatting) of code doesn’t format continuation
lines automatically,manually indent continuation lines one tab stop.
However,always left-align items in a list.

所以我会说这是按照建议(一个标签停止缩进)

相关文章

Format[$] ( expr [ , fmt ] ) format 返回变体型 format$ 强...
VB6或者ASP 格式化时间为 MM/dd/yyyy 格式,竟然没有好的办...
在项目中添加如下代码:新建窗口来显示异常信息。 Namespace...
转了这一篇文章,原来一直想用C#做k3的插件开发,vb没有C#用...
Sub 分列() ‘以空格为分隔符,连续空格只算1个。对所选...
  窗体代码 1 Private Sub Text1_OLEDragDrop(Data As Dat...