mscorlib.dll中出现'System.FormatException'类型的异常

时间:2017-07-02 02:23:30

标签: vb.net

每当我运行此代码时,我都会在VB中收到此错误

  

mscorlib.dll中发生未处理的“System.FormatException”类型异常

     

附加信息:索引(从零开始)必须大于或等于零且小于参数列表的大小。

这段代码:

Module Module1

Sub Main()
    Dim A(0 To 11) As Integer
    Dim B(0 To 11) As Integer
    Dim Count As Integer
    Dim CountB As Integer
    Dim total As Integer
    Console.Write("Enter 11 A and B inputs: " + vbNewLine)
    For Count = 0 To 11
        Console.Write("A : ")
        A(Count) = Convert.ToInt32(Console.ReadLine())
        Console.Write("B : ")

        B(Count) = Console.ReadLine()
        Console.Write(vbNewLine)
    Next
    For Count = 0 To 11
        total = A(Count) * B(CountB)
    Next
    Console.Write(vbNewLine)
    For Count = 0 To 11
        Console.Write("A({0:g}) * B({1:g}) = {3:g} ", A(Count), B(CountB), total & vbNewLine)
    Next
    Console.ReadKey()

End Sub


End Module

这是突出显示错误的地方:

Console.Write("A({0:g}) * B({1:g}) = {3:g} ", A(Count), B(CountB), total & vbNewLine)

1 个答案:

答案 0 :(得分:1)

这是导致异常的原因:

Console.Write("A({0:g}) * B({1:g}) = {3:g} ", A(Count), B(CountB), total & vbNewLine)

应该是:

Console.Write("A({0:g}) * B({1:g}) = {2:g} ", A(Count), B(CountB), total & vbNewLine)