title: declaring var inside if statement c#
body: <p>I have this var, but I want to change it's content depending on the statement, I can't get it working because when I use it, VS says it has not been declared, even if the statement is true...</p>
  
  <pre><code>if (DateTime.Today.Day &gt; 28 &amp;&amp; DateTime.Today.Day &lt; 2)
  {
      var days = GetDaysLikeMe(DateTime.Today).Take(50).Where(d =&gt; d.Date.Day &gt; 28 &amp;&amp; d.Date.Day &lt; 2).Take(4);
  }
  else
  {
      var days = GetDaysLikeMe(DateTime.Today).Take(50).Where(d =&gt; d.Date.Day &lt; 28 &amp;&amp; d.Date.Day &gt; 2).Take(4);
  }
  </code></pre>
  
  <p>EDIT:</p>
  
  <p>I've tried to declare the variable outside the box... But can't get it working neither, the function I keep on var days is this</p>
  
  <pre><code>    public IEnumerable&lt;DateTime&gt; GetDaysLikeMe(DateTime currentDate)
      {
          DateTime temp = currentDate;
          while (true)
          {
              temp = temp.AddDays(-7);
              yield return temp;
          }
      }
  </code></pre>