Thursday, March 29, 2012

Setting optional parameter = null as opposed to nothing?

Hi,

Since you are required to give an optional parameter a value, how can you set it equal to null? Seems like the only thing I can do it set it equal to nothing which is not what I want.
Any suggestions?

Public Shared Sub LogClarifyInteraction(ByVal param1As String,Optional ByVal param2As String ="")' stuff hereEnd sub

Thanks,
Will

From what i know, "NULL" is C# equivalent of "Nothing" in VB.NET

In vb, as per your psuedo code, you would say "nothing" for having the ref variable not refer to anything. And if you would like to refer to an empty string like, "", you could do "String.Empty"

-Cheers


Not sure why I didn't think of this:

Optional ByVal param2As String = nothing

DuhEmbarrassed

0 comments:

Post a Comment