索引超出范围,异常处理仍然错误抛出

时间:2016-01-25 07:04:18

标签: c# datatable

我在运行时遇到了一个奇怪的错误。 Error Message

数据表位于下方 DataTable

我查看了我的代码,并且我特别确保使用Rows.CountsupportPointSelected)不会发生这种情况。我检查Count,如果且仅仅是大于0(代码的第一个IF语句)我继续它。请在下面找到代码。

private List<byte> routeHandler(DataTable supportPointSelected, double taskState, int indices)
{
    //TPCANStatus statusCan = new TPCANStatus();
    int a = supportPointSelected.Columns.IndexOf("Number");     // column number indices
    int b = supportPointSelected.Columns.IndexOf("XSupport"); // column number X
    int c = supportPointSelected.Columns.IndexOf("YSupport"); // column number Y
    int d = supportPointSelected.Columns.IndexOf("VSupport"); // column number Velocity


    if (supportPointSelected.Rows.Count > 0) // Check to Avoid the Error
    {
        if (Convert.ToDouble(supportPointSelected.Rows[0][d]) == 0)
        {
            supportPointSelected.Rows[0][d] = 0.01; // This is the Point the Error Occurs
        }
        else { }
                }
    else { }

    List<byte> output = new List<byte>();
    // Logic do Something
    return output;
}

0 个答案:

没有答案