docs
docs copied to clipboard
Doesn't cover initialization of an empty array
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.
- ID: ae2298bf-325f-ecc2-8c71-43eeb5b843f7
- Version Independent ID: 110c770f-69dc-5379-c0a7-485c55f09e5a
- Content: Constant expression is required - Visual Basic
- Content Source: docs/visual-basic/misc/bc30059.md
- Product: dotnet-visualbasic
- Technology: vb-diagnostics
- GitHub Login: @KathleenDollard
- Microsoft Alias: kdollard
An array cannot be constant expression. Optional arguments require a constant expression.
Alternatives:
- Use
ParamArray. - Set the default value to
Nothing, and inside the function body doIf filters Is Nothing Then filters = ....
@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.