Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • Vb

Idiom #225 Declare and use an optional argument

Declare an optional integer argument x to procedure f, printing out "Present" and its value if it is present, "Not present" otherwise

Imports System
Sub f(Optional x As Integer? = Nothing)
    Console.WriteLine(If(x.HasValue, $"Present {x}", "Not Present"))
End Sub

The note for C# also applies to VB.NET.
(defn f [& [x]]
  (if (integer? x)
    (println "Present" x)
    (println "Not present")))

Optional argument with positional parameters

New implementation...
< >
tkoenig