0

The d in the second if statement is out of scope (the error is 'Use of unassigned local variable 'd'') Why? And how do I fix this?

 @{string d;}
   @foreach (var l in c.TimeAvailables) { 
   <div class="day @l.Day @c.id " data-day="@l.Day" data-bgtime="@l.BegginingTime" data-endtime="@l.EndTime">
   <div class="dayDisplayed">
   @if (l.BegginingTime != null)
       {
                      {d = l.Day; }
  <b class="time @l.id">From:</b> <span class="beTime" data-id="@l.id">@string.Format("{0:hh:mm tt}", new DateTime().Add(l.BegginingTime.HasValue ? l.BegginingTime.Value : new TimeSpan(0, 0, 0)))</span>
    <br />
   <b class="time @l.id">Until:</b><span class="enTime" data-id="@l.id">@string.Format("{0:hh:mm tt}", new DateTime().Add(l.EndTime.HasValue                ? l.EndTime.Value : new TimeSpan(0, 0, 0)))</span>
       }
@if (l.BegginingTime == null && d != l.Day)
  {
<b class="time @l.id"></b> <span class="beTime" data-          
 id="@l.id">Unavailable</span>
 <br />
 <b class="time @l.id"></b><span class="enTime" data-id="@l.id"></span>
    }
   </div>

}

tereško
  • 58,060
  • 25
  • 98
  • 150
N. Sch
  • 667
  • 2
  • 5
  • 15

1 Answers1

1

I think your problem is d is unassigned:

Try

 @{string d = string.Empty;} 

Alternatively as @Lucas suggested you could assign to null.

Botonomous
  • 1,746
  • 1
  • 16
  • 39