gpt4 book ai didi

asp.net-mvc-2 - 无法将类型 'double?' 隐式转换为 'double'

转载 作者:行者123 更新时间:2023-12-05 09:24:34 25 4
gpt4 key购买 nike

我正在使用 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?)

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

最佳答案

看起来您要添加的内容之一可能是 Nullable<Double>

来自double?double你需要做的

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

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

关于asp.net-mvc-2 - 无法将类型 'double?' 隐式转换为 'double',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10920723/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com