在错误对象引用上将我的头撞在墙上未设置为对象的实例。 见下面的代码。违规行标有<!--->>>>>>>>
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>";
}
答案 0 :(得分:2)
使用String.Format("{0}{1}", obj1, obj2 ?? "")
。并使用调试器,将断点放到此行并检查对象,然后添加验证逻辑。也许问题出在database.getjobName
方法代码中。您始终可以使用null coalescing operator。永远不要像你的例子中那样使用字符串连接,它非常难看并且容易出错。