rspec/rules/S5939/vbnet/rule.adoc
2020-12-23 14:59:06 +01:00

26 lines
871 B
Plaintext

Method for creating empty arrays ``Array.Empty(Of TElement)`` was introduced in .NET 4.6 to optimize object instantiation and memory allocation. It also improves code readability by making developer's intent more explicit. This new method should be preferred over empty array declaration.
== Noncompliant Code Example
----
Public Sub Method()
Dim Values1(-1) As Integer ' Noncompliant
Dim Values2 As Integer() = New Integer() {} ' Noncompliant
Dim Values3 As Integer() = {} ' Noncompliant
Dim Values4() As Integer = {} ' Noncompliant
End Sub
----
== Compliant Solution
----
Public Sub Method()
Dim Values1 As Integer() = Array.Empty(Of Integer)
Dim Values2 As Integer() = Array.Empty(Of Integer)
Dim Values3 As Integer() = Array.Empty(Of Integer)
Dim Values4() As Integer = Array.Empty(Of Integer)
End Sub
----
include::../see.adoc[]