LoginSignup
0
0

More than 1 year has passed since last update.

VB.NETで改行

Posted at

VB.NETの現場でコードの途中で改行する場合に _を行末に入れて改行をするのをよく見かけたが、使わなくてもC#程自由ではないけれど、そこそこ改行できるのでまとめてみた。
基本的に演算子の直後に改行が可能。
空行は含められない。

引数

(,の後、)の前で改行が可能 

Private Sub Main()
    Dim name = GetFullName(
                           "John",
                           "Doe"
                          )  
End Sub

Private Function GetFullName(
                             ByVal firstName As String,
                             ByVal lastName As String
                             ) As String

    Return firstName & " " & lastName As String
End Function
 

配列

{,の後、}の前で改行が可能

Dim names() = {
               "John",
               "Doe"
               }

代入

=の後に改行が可能

Dim name =
    "John Doe"

Dim age As Integer =
    30

四則演算、文字列の結合

算術演算子や&の後に改行が可能

Dim age = 30 +
    1
Dim name = "John" 
name &=
    " " &
    "Doe"

条件式

比較演算子や論理演算子の後に改行が可能
Notの後は改行できない

Dim name = "John Doe"
Dim age = 30

If name <> 
    "" AndAlso
   age >=
   20 Then

    Console.WriteLine(name)
End If

For Each

Inの前後で改行が可能

Dim names = {"Jone", "Jane"}
For Each name
         In
         names

    Console.WriteLine(name)
Next

プロパティ、メッソド

.の後に改行が可能

Dim john As New Person("John", "Doe", 30)
Console.WriteLine(john.
                  FullName)

Console.WriteLine(john.
                  Age.
                  ToString())

LINQ クエリ式

Dim people As New List(Of Person)({New Person("John", "Doe", 30), New Person("Jane", "Doe", 20)})

Dim FullNameList = From
                        person
                        In
                        people
                    Where
                         person.Age >=
                         20 AndAlso
                         person.LastName =
                         "Doe"
                     Select
                         person.FullName
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0