0

由于错误对象引用未设置为对象实例而使我头疼不已。请参阅下面的代码。违规行标有 <!--->>>>>>>

string htmlOutput = " ";

    htmlOutput +=  "<h3>employee: " + employee.lastName + ", " + employee.firstName + " (" + thisForm.employeeID + ")</h3>" +
        "<h3>Submitted To: " + thisForm.boss + "</h3>" +

    if (job1.JRN != "" || job1.JRN != "INVALID")
    {
        <!--->>>>>>>htmlOutput += "<hr /><h4>Job 1</h4> " + "<h3>" + database.getjobName(job1.JRN) + " (" + job1.JRN + ")</h3>";
        htmlOutput += "<h3>Date of Last Attendance: " + job1.month + " " + job1.day + ", " + job1.year + "</h3>";
        htmlOutput += "<h3>Pass/Fail: " + job1.passFail + "</h3>";
    }
4

1 回答 1

2

使用String.Format("{0}{1}", obj1, obj2 ?? ""). 并使用调试器,在这一行设置断点并检查对象,然后添加验证逻辑。也许问题出在database.getjobName方法代码中。您始终可以使用空合并运算符。切勿像您的示例中那样使用字符串连接,它非常丑陋且容易出错。

于 2012-04-16T15:35:28.750 回答