Visual Basic .NET里如何实现多行IF语句的缩进格式化?
- 内容介绍
- 文章标签
- 相关推荐
本文共计337个文字,预计阅读时间需要2分钟。
如果您有一个多行的IF语句,默认缩进可能会使阅读有些困难:`If SomeConditionA AndAlso SomeConditionB AndAlso SomeConditionC Then DoSomething() End If`
我可以将这种结构简化,以便更易于阅读,例如:`If (SomeConditionA And SomeConditionB And SomeConditionC) Then DoSomething() End 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.
所以我会说这是按照建议(一个标签停止缩进)
本文共计337个文字,预计阅读时间需要2分钟。
如果您有一个多行的IF语句,默认缩进可能会使阅读有些困难:`If SomeConditionA AndAlso SomeConditionB AndAlso SomeConditionC Then DoSomething() End If`
我可以将这种结构简化,以便更易于阅读,例如:`If (SomeConditionA And SomeConditionB And SomeConditionC) Then DoSomething() End 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.
所以我会说这是按照建议(一个标签停止缩进)

