VB.NET – Rap into the coding style of multi-line IF statements in Visual Basic .NET

If you have a multi-line IF statement, the default indentation may be a bit difficult to read:

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

I can think of some solutions to this problem, for example:

>Indent the second and third lines by 8 instead of 4 spaces,
> does not indent the second and third lines at all,
> adds a blank line after the third line,
> ……

But I want to know if there are some perfect or even officially recommended coding styles in this situation.

Actually according to coding conventions, you should

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

So the code should look like this:

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

Then it says:

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.

So I will say this is as suggested (a tag stops indentation)

If you have a multi-line IF statement, the default indentation may be a bit difficult to read:

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

I can think of some ways to solve this problem, for example:

> Three lines are indented by 8 instead of 4 spaces,
> does not indent the second and third lines at all,
> adds a blank line after the third line,
> ……

But I want to know if there are some perfect or even officially recommended coding styles for this situation.

Actually according to coding conventions, you should

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

So the code should look like this:

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

Then it says:

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.

So I will say this is as suggested (a tab stops indentation)

Leave a Comment

Your email address will not be published.