0

我正在尝试将此代码转换为 VB,但它给了我这个错误。

转换错误:无法转换代码。细节:

-- 第 1 行第 8 列:无效的 TypeDecl

请检查原始代码中的任何错误,然后重试。

  public Exam GetExamByExamID(int ExamID)
                {
             Exam myExam = new Exam(0,"",0,"","");  
              for(Exam exam1 : ExamArray)
            if(Exam.ExamID==ExamID)
              {
                 myExam.ExamID = exam1.ExamID;
                 myExam.ExamTitle = exam1.ExamTitle;
                     myExam.CreditHours = exam1.CreditHours;
                     myExam.Description = exam1.Description;
                         myExam.PrerequisiteExam = exam1.PrerequisiteExam;

              }
                  return myExam;

我将代码更改为此,但它仍然是相同的错误..

public Exam GetExamByExamID(int ExamID)
                    {
                 Exam myExam = new Exam(0,"",0,"","");  
                  for(Exam exam1 : ExamArray)
                if(Exam.ExamID==ExamID)
                  {
                     myExam.ExamID = exam1.ExamID;
                     myExam.ExamTitle = exam1.ExamTitle;
                         myExam.CreditHours = exam1.CreditHours;
                         myExam.Description = exam1.Description;
                             myExam.PrerequisiteExam = exam1.PrerequisiteExam;

                  }
                      return myExam;
                       }

我究竟需要改变什么?请帮忙。

好的,我再次更改但同样的错误..它在第 1 行显示错误..

public Exam GetExamByExamID(int ExamID)
                    {
                 Exam myExam = new Exam(0,"",0,"","");  
                  for(Exam exam1 : ExamArray)
                if(exam1.ExamID==ExamID)
                  {
                     myExam.ExamID = exam1.ExamID;
                     myExam.ExamTitle = exam1.ExamTitle;
                         myExam.CreditHours = exam1.CreditHours;
                         myExam.Description = exam1.Description;
                             myExam.PrerequisiteExam = exam1.PrerequisiteExam;

                  }
                      return myExam;
                       }
4

3 回答 3

1

我认为您应该发布整个课程,而不仅仅是片段。无论如何,我将首先挖掘它。

Exam.ExamID and other Exam.* 

你确定他们指的是一个变量吗?如果你指的是这个类的字段,你应该使用this.ExamID等等

如果不是,这很可能是您的错误。

于 2012-06-11T18:46:08.920 回答
0

您从代码转换器获得的错误是因为您没有包含要转换的类Exam,所以转换器错误是在第一次遇到未知类Exam时说“无效的类型声明” 。

这可能对你有用:

 Public Function GetExamByExamID(ExamID As Integer) As Exam
    Dim myExam As New Exam(0, "", 0, "", "")
    For Each exam1 As exam In ExamArray
        If exam1.ExamID = ExamID Then
            With myExam
                .ExamID = exam1.ExamID
                .ExamTitle = exam1.ExamTitle
                .CreditHours = exam1.CreditHours
                .Description = exam1.Description
                .PrerequisiteExam = exam1.PrerequisiteExam
            End With
            Return myExam
        End If
    Next
    Return Nothing
End Function
于 2012-06-11T19:19:10.453 回答
0

这只是一个猜测,但请尝试更改

public Exam GetExamByExamID(int ExamID)

public Exam GetExamByExamID(int id)

随着变化

if(exam1.ExamID==ExamID)

if(exam1.ExamID==id)
于 2012-06-11T18:44:18.500 回答