如何操纵二维数组

时间:2018-08-29 20:37:15

标签: arrays vb.net

我需要创建一个向用户显示菜单的程序,要求用户向其添加项目,然后显示新菜单。为此,我必须使用2D数组,并且不允许使用函数或对象。这就是我到目前为止

Module Module1

    Sub Main()
        Dim arr1(3, 2) As String

        arr1(0, 0) = "Kebab"
        arr1(0, 1) = "9.99"
        arr1(0, 2) = "5"
        arr1(1, 0) = "Beef"
        arr1(1, 1) = "6.99"
        arr1(1, 2) = "7"
        arr1(2, 0) = "Chicken"
        arr1(2, 1) = "4.00"
        arr1(2, 2) = "9"
        arr1(3, 0) = "Beer"
        arr1(3, 1) = "0.99"
        arr1(3, 2) = "10"

        Console.WriteLine("Menu: ")
        Console.WriteLine("Kebab    9.99    5")
        Console.WriteLine("Beef     6.99    7")
        Console.WriteLine("Chicken  4.00    9")
        Console.WriteLine("Beer     0.99    10")
        Console.WriteLine()
        Console.WriteLine("Enter a new item")

        For i As Integer = 0 To arr1.Length - 1
            arr1(i, i) = Console.ReadLine()
        Next

        Console.Read()

    End Sub

End Module

0 个答案:

没有答案