title: Is there a way to change the scope of a variable in cshtml?
body: <p>As im creating a dynamic page, I try to access two variables that are modified by a foreach loop. The variable becomes <b>unassigned</b> after the loop even if I declared them outside.</p>
  
  <p>I know I should find a way to make an <b>sql joint</b>, but this problem keeps occurring whenever I try to access a variable prior to a loop. I searched a way to stop the garbage collector from deleting the variable altogether, but I need a cleaner way to do this.</p>
  
  <pre class="lang-cs prettyprint-override"><code>@foreach (var item in db.Horraire)
  {
      String Employe;
      String color;
          foreach (var search in db.Employé)
          {
              if (search.id == item.EmployeID) { Employe = search.naming; break; }
          }
          foreach (var search in db.Tâche)
          {
              if (search.id == item.EmployeID) { color = search.coloring; break; }
          }
  //Turning worked hour into size of occupied red square on a calendar, it's working properly
      TimeSpan substract = item.fin.Subtract(item.début);
      float phours = substract.Hours * 70; phours = phours + substract.Minutes * (60/70);
      String pheight = ""+phours+"px";
      float thours = item.début.Subtract(new DateTime()).Hours + item.début.Subtract(new DateTime()).Minutes/60 - 8; thours = thours * 70 + 110;
      String theight = ""+thours+"px";
      int lday = item.Jour * 200 + 200;
      String ljour = "" + lday + "px";
  &lt;div class="redsquare" style="
      position: absolute; width:200px; height:@pheight;
      top:@theight;
      left:@ljour;
      font-size: 0.8em;
      text-align: right;
      color: @color;"&gt; //missing local variable
      @Employe //missing local variable
  &lt;/div&gt;
  }
  </code></pre>
  
  <p>Both variables becomes error <i>"Use of unassigned local variable"</i> instead of just injecting the variable into the html. How can I fix, either the joint, the <b>scope of the variable</b> or the garbage collection?</p>