Optional Byte Array Parameter

I canNOT get this right.  I just want my first parameter to be an optional byte array.  The most recent code I've tried is below, and the syntax error I get is "Constant expression is required".

How the heck do I supply a default value for this optional byte array, so that it's an empty byte array by default?  (Ubound(a) = 0, or better yet, Ubound(a) < 0)?

Thanks a bunch.

   Private Function StartXMLDecompressorThread( _
      Optional ByRef ByteArrayData() As Byte = New Byte() {}, _
      Optional ByVal sEXEPath As String = "", _
      Optional ByVal sXMLPath As String = "", _
      Optional ByVal sOutputPath As String = "" _
      ) _
      As Integer

Who is Participating?
naveenkohliConnect With a Mentor Commented:
This is by rule that you can only supply contant values for optional arguments. You can't use "new" operator in the argument definition. You should be able to set this array argument to "null" by default. And then in function call you will check if this argument value is null or not.
Optional ByRef ByteArrayData() As Byte =nothing
Did you ever consider altering this to be an overloaded function?  Or is it just too many optional arguments to consider (maybe rework it a bit)?
brykerAuthor Commented:
Man, do I feel like an idiot.  I keep forgetting that EVERYTHING in .NET is an object, and so can be legitimately set to Nothing.

Thanks for the help.
And have you tried:

Optional ByRef ByteArrayData() As Byte = Nothing
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.