1

我正在使用 asp.net MVC2,并且在以下代码行中出现错误

<% double RunningTotal = 0; %>
<%foreach (var item in Model)
       {%>
      <%var allowedHours = item.tblPerson.tblPersonAllowedHours.Where(x=>x.Semester == item.Semester).Sum(x=>x.AllowedHoursPerWeek);  %>         
            <tr>
                <td><%: item.Semester %></td>
                <td><%: allowedHours.ToString() %></td>
                <td><%: item.tblPerson.tblCourseWantedHours.Where(x => x.Semester == item.Semester).Sum(x => x.WantedHoursPerWeek+x.UL+x.UT) %></td>
                <td><%: item.tblPerson.tblCourseWantedHours.Where(x => x.Semester == item.Semester).Sum(x => x.WantedHoursPerWeek+x.UL+x.UT) - allowedHours %></td>
                <%: RunningTotal += (item.tblPerson.tblCourseWantedHours.Where(x => x.Semester == item.Semester).Sum(x => x.WantedHoursPerWeek + x.UL + x.UT) - allowedHours) %>

                <td></td>

我得到的错误就在这条线上

<%: RunningTotal += (item.tblPerson.tblCourseWantedHours.Where(x => x.Semester == item.Semester).Sum(x => x.WantedHoursPerWeek + x.UL + x.UT) - allowedHours) %>

错误描述是

CS0266: Cannot implicitly convert type 'double?' to 'double'. An explicit conversion exists (are you missing a cast?)

知道我在这里缺少什么吗?

4

1 回答 1

7

看起来您尝试添加的其中一件事可能是Nullable<Double>

去你double?需要double做的

double? nullableDouble = 3.0;
if (nullableDouble.HasValue)
    double notNullableDouble = nullableDouble.Value;

有关 Nullables 的更多信息:http: //msdn.microsoft.com/en-us/library/b3h38hb0.aspx

于 2012-06-06T19:23:30.500 回答