I can offer you three ways of doing it.
First is to use Tuple(Of Integer, Integer).
Public Function jaggedarr(ByRef arr()() As Integer, ByVal keyvalue As Integer) As Tuple(Of Integer, Integer)
For i As Integer = 0 To arr.GetUpperBound(0)
For j As Integer = 0 To arr(i).GetUpperBound(0)
If arr(i)(j) = keyvalue Then
Return Tuple.Create(i, j)
End If
Next
Next
End Function
The second is to define you own return class.
Public Function jaggedarr(ByRef arr()() As Integer, ByVal keyvalue As Integer) As Pair
For i As Integer = 0 To arr.GetUpperBound(0)
For j As Integer = 0 To arr(i).GetUpperBound(0)
If arr(i)(j) = keyvalue Then
Return New Pair(i, j)
End If
Next
Next
End Function
Public NotInheritable Class Pair
Implements IEquatable(Of Pair)
Private ReadOnly _I As Integer
Private ReadOnly _J As Integer
Public ReadOnly Property I As Integer
Get
Return _I
End Get
End Property
Public ReadOnly Property J As Integer
Get
Return _J
End Get
End Property
Public Sub New(I As Integer, J As Integer)
_I = I
_J = J
End Sub
Public Overrides Function Equals(obj As Object) As Boolean
If TypeOf obj Is Pair
Return Equals(DirectCast(obj, Pair))
End If
Return False
End Function
Public Overloads Function Equals(obj As Pair) As Boolean Implements IEquatable(Of Pair).Equals
If obj Is Nothing
Return False
End If
If Not EqualityComparer(Of Integer).[Default].Equals(_I, obj._I)
Return False
End If
If Not EqualityComparer(Of Integer).[Default].Equals(_J, obj._J)
Return False
End If
Return True
End Function
Public Overrides Function GetHashCode() As Integer
Dim hash As Integer = 0
hash = hash Xor EqualityComparer(Of Integer).[Default].GetHashCode(_I)
hash = hash Xor EqualityComparer(Of Integer).[Default].GetHashCode(_J)
Return hash
End Function
Public Overrides Function ToString() As String
Return [String].Format("{{ I = {0}, J = {1} }}", _I, _J)
End Function
End Class
The third, and probably the most interesting way is to pass a return delegate.
Public Sub jaggedarr(ByRef arr()() As Integer, ByVal keyvalue As Integer, ByVal [return] As Action(Of Integer, Integer))
For i As Integer = 0 To arr.GetUpperBound(0)
For j As Integer = 0 To arr(i).GetUpperBound(0)
If arr(i)(j) = keyvalue Then
[return](i, j)
End If
Next
Next
End Sub
This method changes from a Function to Sub and the [return] As Action(Of Integer, Integer) allows multiple return values of multiple pairs.
You could even couple this with the Pair class and do this:
Public Sub jaggedarr(ByRef arr()() As Integer, ByVal keyvalue As Integer, ByVal [return] As Action(Of Pair))
For i As Integer = 0 To arr.GetUpperBound(0)
For j As Integer = 0 To arr(i).GetUpperBound(0)
If arr(i)(j) = keyvalue Then
[return](New Pair(i, j))
End If
Next
Next
End Sub
Dim x As Integer(,) = Array.CreateInstance(GetType(Integer), { 5, 6 }, { 15, 5 })which creates an array with non-zero bounds.