我在我的代码中使用了 for 循环,但它显示使用未分配的局部变量的错误。
这是我的代码:
public List<CustomTypeLayer.EmployeeLeave> GetLeaveRecord(int emplid)
{
DataSet ds = objLMSRepository.GetLeaveRecord(emplid);
List<EmployeeLeave> leavelist = new List<EmployeeLeave>();
if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
{
for (int k; k < 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;
}
错误出现在 for 循环中k
。你可以在 for 循环中看到我已经k
用int k
.