UBound Array vb6转换为C#

use*_*783 3 c# vb6 visual-studio-2010 vb6-migration

我在VB6中有以下代码:

Dim frpdReport() As REPORTDEF

For iCounter = 0 To UBound(frpdReport)

    With frpdReport(iCounter)
        If .iReportID = iReportID Then
            fGetReportFile = .tReportFile
        End If
    End With
Next iCounter
Run Code Online (Sandbox Code Playgroud)

我转换为这个C#代码:

REPORTDEF[] frpdReport = new REPORTDEF[6];
 for (iCounter = 0; iCounter < Convert.ToInt32(frpdReport[6]); iCounter++)
    {
        if (frpdReport[iCounter].iReportID == iReportID)
        {
            fGetReportFile_return = frpdReport[iCounter].tReportFile;
        }

    }
    return fGetReportFile_return;
Run Code Online (Sandbox Code Playgroud)

调试时,我在for语句中得到以下错误 - "索引超出了数组的范围." 我无法弄清楚为什么因为数组的索引是6.

有什么帮助吗?

Jam*_*mes 5

为什么不使用.length属性?

 for (iCounter = 0; iCounter < frpdReport.Length; iCounter++)
Run Code Online (Sandbox Code Playgroud)

或者如果您不需要计数器值,则为每个值

foreach (REPORTDEF frpReportItem in frpdReport)
Run Code Online (Sandbox Code Playgroud)

或者,如果您要查找特定项目,请使用LINQ

REPORTDEF fGetReportFile_return = frpdReport.Where( fR => fR.iReportID == iReportID).Single();
Run Code Online (Sandbox Code Playgroud)