加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-17 07:10:48 所属栏目:百科 来源:网络整理
导读:如果你有一个多行IF语句,默认缩进可能有点难以阅读: If SomeConditionA _ AndAlso SomeConditionB _ AndAlso SomeConditionC Then DoSomething()End If 我可以想到一些解决这个问题的方法,例如: 将第二行和第三行缩进8而不是4个空格, 根本没有缩进第二和第
如果你有一个多行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.

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读