locked
Function return jagged array RRS feed

  • Question

  • User-256799415 posted

    Can we make function which return jagged array? If so, could u give example of it?

    Wednesday, April 4, 2012 7:05 AM

Answers

  • User-2146987983 posted

    Function returning jagged array:

    Public Function [Get]() As Integer()()
            Dim a As Integer()() = New Integer(1)() {}
            a(0) = New Integer(1) {1, 2}
            a(1) = New Integer(0) {3}
            Return a
    End Function

    Calling Process:

    Dim b As Integer()() = [Get]()
    For Each x As Integer() In b
        For Each y As Integer In x
                Console.WriteLine(y.ToString())
        Next
    Next

    Thanks

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, April 4, 2012 7:19 AM

All replies

  • User-2146987983 posted

    Function returning jagged array:

    Public Function [Get]() As Integer()()
            Dim a As Integer()() = New Integer(1)() {}
            a(0) = New Integer(1) {1, 2}
            a(1) = New Integer(0) {3}
            Return a
    End Function

    Calling Process:

    Dim b As Integer()() = [Get]()
    For Each x As Integer() In b
        For Each y As Integer In x
                Console.WriteLine(y.ToString())
        Next
    Next

    Thanks

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, April 4, 2012 7:19 AM
  • User-256799415 posted

    Ayayaaa! This is what i need.

    Thank you for ur help :)

    Wednesday, April 4, 2012 1:13 PM