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