docs icon indicating copy to clipboard operation
docs copied to clipboard

Doesn't cover initialization of an empty array

Open alkdev opened this issue 5 years ago • 2 comments

Public Function MyFun(Optional filters() As (String, String) = New (String, String)() { } ) As Boolean

returns BC30059, as well as when specifying the array size.


Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

alkdev avatar Oct 02 '20 08:10 alkdev

An array cannot be constant expression. Optional arguments require a constant expression.

Alternatives:

  1. Use ParamArray.
  2. Set the default value to Nothing, and inside the function body do If filters Is Nothing Then filters = ....

Youssef1313 avatar Oct 02 '20 12:10 Youssef1313

@Youssef1313 , Thanks for the hints, but this is not a problem, I solved it. The problem is that the documentation page looks quite poor missing some cases like this.

alkdev avatar Oct 03 '20 08:10 alkdev