Two dimensional array as buffer for screen Learn programming Visual Basic (VB.net)

Lesson:

Arrays, Structures and Strings


Exercise:

Two dimensional array as buffer for screen 45


Objetive:

Create a Visual Basic (VB.net) program that declares a 70x20 two-dimensional array of characters, "draws" 80 letters (X, for example) in random positions and displays the content of the array on screen.


Code:

Imports System
Public Class exercise92
    Public Shared Sub Main()
        Dim position As Char(,) = New Char(19, 69) {}
        Dim generator As Random = New Random()
        Dim i As Integer = 0

        While i < 80
            position(generator.[Next](0, 20), generator.[Next](0, 70)) = "X"c
            i += 1
        End While

        For i = 0 To 20 - 1

            For j As Integer = 0 To 70 - 1
                Console.Write(position(i, j))
            Next

            Console.WriteLine()
        Next
    End Sub
End Class