Note: I used a C # to VB converter, so hopefully the correct VB syntax.
I made a simple extension method that makes this pretty simple:
Public NotInheritable Class Extensions Private Sub New() End Sub <System.Runtime.CompilerServices.Extension> _ Public Shared Function GetNonNullItems(Of T)(array As T(,), index As Integer) As IEnumerable(Of T) For i As Integer = 0 To array.GetLength(index) - 1 If array(index, i) IsNot Nothing Then yield Return array(index, i) End If Next End Function End Class
Then, to use it:
Dim Array As String(,) = New String(4, 10) {} Array(0, 0) = "100" Array(0, 1) = "200" Array(1, 0) = "300" Array(1, 1) = "400" Array(1, 2) = "500" Array(1, 3) = "600" Dim countArray0 As Integer = Array.GetNonNullItems(0).Count() Dim countArray1 As Integer = Array.GetNonNullItems(1).Count()
The extension method will provide you with all non-zero elements found for this index. From this you can get an invoice, filter, request or use them as you want.
source share