Optional (Visual Basic)
指定在调用过程时可以省略过程参数。
备注
必须为所有可选过程参数指定默认值。
Optional 修饰符可用于下面的上下文中:
下面的示例定义有两个可选参数的过程。
Public Function FindMatches(ByRef values As List(Of String),
ByVal searchString As String,
Optional ByVal matchCase As Boolean = False) As List(Of String)
Dim results As IEnumerable(Of String)
If matchCase Then
results = From v In values
Where v.Contains(searchString)
Else
results = From v In values
Where UCase(v).Contains(UCase(searchString))
End If
Return results.ToList()
End Function