我想將此代碼轉換爲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;
}
究竟是什麼,我需要改變?請幫忙。
好,我又變了,但同樣的error..it說錯誤在第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;
}
見user1440922回答以下。此外,一旦你找到考試並設置myExam,你應該打破你的for循環。 – Josh
只需編輯您的原始代碼,而不是粘貼在稍有不同的新副本中! – Michael