S2429 — Arrays should be initialized using the "... = {}" syntax

Language
VB.NET
Type
Code smell
Severity
Minor
Tags
clumsy

Why is this an issue?

The ... = {} syntax is more compact, more readable and less error-prone.

Noncompliant code example


Module Module1
  Sub Main()
    Dim foo(1) As String   ' Noncompliant
    foo(0) = "foo"
    foo(1) = "bar"
  End Sub
End Module

Compliant solution


Module Module1
  Sub Main()
    Dim foo = {"foo", "bar"}  ' Compliant
  End Sub
End Module

↑ Back to top