Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot implicitly convert type 'double?' to 'double'

i am using asp.net MVC2 and i am getting an error on the follwoing line of code

<% 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>

the error i am getting is on this line

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

error description is

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

any idea what i am missing here?

like image 239
jawad hasan Avatar asked Sep 18 '26 07:09

jawad hasan


1 Answers

It looks like one of the things you are trying to add might be a Nullable<Double>

to go from double? to double you need to do

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

More info on Nullables: http://msdn.microsoft.com/en-us/library/b3h38hb0.aspx

like image 91
Hans Z Avatar answered Sep 22 '26 11:09

Hans Z