EDIT: this should be possible in VB.NET 10 as per this blog post . If you use it, you can:
Public Sub DoSomething(Optional ByVal someInteger As Integer? = Nothing) Console.WriteLine("Result: {0} - {1}", someInteger.HasValue, someInteger) End Sub ' use it DoSomething(Nothing) DoSomething(20)
For versions other than VB.NET 10:
Your request is not possible. You must either use an optional parameter or a NULL value. This signature is not valid:
Public Sub DoSomething(Optional ByVal someInteger As Nullable(Of Integer) _ = Nothing)
You will get this compilation error: "Optional parameters cannot have structure types."
If you use nullable, set to Nothing if you do not want to pass a value to it. Choose between these options:
Public Sub DoSomething(ByVal someInteger As Nullable(Of Integer)) Console.WriteLine("Result: {0} - {1}", someInteger.HasValue, someInteger) End Sub
or
Public Sub DoSomething(Optional ByVal someInteger As Integer = 42) Console.WriteLine("Result: {0}", someInteger) End Sub
source share