title: Use of unassigned local variable
body: <p>I have use for loop in my code and but its showing error of Use of unassigned local variable.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>public List&lt;CustomTypeLayer.EmployeeLeave&gt; GetLeaveRecord(int emplid)
  {
      DataSet ds = objLMSRepository.GetLeaveRecord(emplid);
      List&lt;EmployeeLeave&gt; leavelist = new List&lt;EmployeeLeave&gt;();
      if (ds != null &amp;&amp; ds.Tables.Count &gt; 0 &amp;&amp; ds.Tables[0].Rows.Count &gt; 0)
      {
          for (int k; k &lt; ds.Tables[0].Rows.Count; k++)
          {
              DataRow dr = ds.Tables[0].Rows[k];
              EmployeeLeave leave = new EmployeeLeave();
              leave.DateFrom = Convert.ToDateTime(dr["dt_from"]);
              leave.DateTo = Convert.ToDateTime(dr["dt_to"]);
              leave.EmployeeId = Convert.ToInt32(dr["EmployeeID"]);
              leave.Reason = Convert.ToString(dr["txt_reason"]);
              leave.LeaveType = (LeaveReason)Enum.Parse(typeof(LeaveReason), dr["id_leave_type"].ToString(), true);
              leavelist.Add(leave);
          }
      }
      return leavelist;
  }
  </code></pre>
  
  <p>The error is in the for loop in <code>k</code>. You can see in for loop I have initialized <code>k</code> with <code>int k</code>.</p>