Syntax element | Example |
|---|
After a comma (,). |
Public Function GetUsername(ByVal username As String,
ByVal delimiter As Char,
ByVal position As Integer) As String
Return username.Split(delimiter)(position)
End Function
|
After an open parenthesis (() or before a closing parenthesis ()). |
Dim username = GetUsername(
Security.Principal.WindowsIdentity.GetCurrent().Name,
CChar("\"),
1
)
|
After an open curly brace ({) or before a closing curly brace (}). |
Dim customer = New Customer With {
.Name = "Terry Adams",
.Company = "Adventure Works",
.Email = "terry@www.adventure-works.com"
}
For more information, see Object Initializers: Named and Anonymous Types or Collection Initializers Overview (Visual Basic). |
After an open embedded expression (<%=) or before the close of an embedded expression (%>) within an XML literal. |
Dim customerXml = <Customer>
<Name>
<%=
customer.Name
%>
</Name>
<Email>
<%=
customer.Email
%>
</Email>
</Customer>
For more information, see Embedded Expressions in XML. |
After the concatenation operator (&). |
cmd.CommandText =
"SELECT * FROM Titles JOIN Publishers " &
"ON Publishers.PubId = Titles.PubID " &
"WHERE Publishers.State = 'CA'"
For more information, see Operators Listed by Functionality. |
After assignment operators (=, &=, :=, +=, -=, *=, /=, \=, ^=, <<=, >>=). |
Dim fileStream =
My.Computer.FileSystem.
OpenTextFileReader(filePath)
For more information, see Operators Listed by Functionality. |
After binary operators (+, -, /, *, Mod, <>, <, >, <=, >=, ^, >>, <<, And, AndAlso, Or, OrElse, Like, Xor) within an expression. |
Dim memoryInUse =
My.Computer.Info.TotalPhysicalMemory +
My.Computer.Info.TotalVirtualMemory -
My.Computer.Info.AvailablePhysicalMemory -
My.Computer.Info.AvailableVirtualMemory
For more information, see Operators Listed by Functionality. |
After the Is and IsNot operators. |
If TypeOf inStream Is
IO.FileStream AndAlso
inStream IsNot
Nothing Then
ReadFile(inStream)
End If
For more information, see Operators Listed by Functionality. |
After a member qualifier character (.) and before the member name. However, you must include a line-continuation character (_) following a member qualifier character when you are using the With statement or supplying values in the initialization list for a type. Consider breaking the line after the assignment operator (for example, =) when you are using With statements or object initialization lists. |
Dim fileStream =
My.Computer.FileSystem.
OpenTextFileReader(filePath)
...
' Not allowed:
' Dim aType = New With { .
' PropertyName = "Value"
' Allowed:
Dim aType = New With {.PropertyName =
"Value"}
Dim log As New EventLog()
' Not allowed:
' With log
' .
' Source = "Application"
' End With
' Allowed:
With log
.Source =
"Application"
End With
For more information, see With...End With Statement (Visual Basic) or Object Initializers: Named and Anonymous Types. |
After an XML axis property qualifier (. or .@ or ...). However, you must include a line-continuation character (_) when you specify a member qualifier when you are using the With keyword. |
Dim customerName = customerXml.
<Name>.Value
Dim customerEmail = customerXml...
<Email>.Value
For more information, see XML Axis Properties. |
After a less-than sign (<) or before a greater-than sign (>) when you specify an attribute. Also after a greater-than sign (>) when you specify an attribute. However, you must include a line-continuation character (_) when you specify assembly-level or module-level attributes. |
<
Serializable()
>
Public Class Customer
Public Property Name As String
Public Property Company As String
Public Property Email As String
End Class
For more information, see Attributes (C# and Visual Basic). |
Before and after query operators (Aggregate, Distinct, From, Group By, Group Join, Join, Let, Order By, Select, Skip, Skip While, Take, Take While, Where, In, Into, On, Ascending, and Descending). You cannot break a line between the keywords of query operators that are made up of multiple keywords (Order By, Group Join, Take While, and Skip While). |
Dim vsProcesses = From proc In
Process.GetProcesses
Where proc.MainWindowTitle.Contains("Visual Studio")
Select proc.ProcessName, proc.Id,
proc.MainWindowTitle
For more information, see Queries (Visual Basic). |
After the In keyword in a For Each statement. |
For Each p In
vsProcesses
Console.WriteLine("{0}" & vbTab & "{1}" & vbTab & "{2}",
p.ProcessName,
p.Id,
p.MainWindowTitle)
Next
For more information, see For Each...Next Statement (Visual Basic). |
After the From keyword in a collection initializer. |
Dim days = New List(Of String) From
{
"Mo", "Tu", "We", "Th", "F", "Sa", "Su"
}
For more information, see Collection Initializers Overview (Visual Basic). |