This code is .Net 2.0 safe:
public static string ReadLines(StreamReader input)
{
string line;
while ( (line = input.ReadLine()) != null)
yield return line;
}
private taMibMsftEmpDetails BuildLine(string EmpId, string EmpName, String ExpnsDate)
{
taMibMsftEmpDetails empSlNr = new taMibMsftEmpDetails();
empSlNr.EmployeeId = EmpId;
empSlNr.EmployeeName = EmpName;
empSlNr.ExpenseDate = ExpnsDate;
return empSlNr;
}
List<taMibMsftEmpDetails> lineEmpNrs = new List<taMibMsftEmpDetails>();
foreach (string line in ReadLines(HeaderFile))
{
headerFields = line.Split(',');
lineEmpNrs.Add(BuildLine(headerFields[1],headerFields[2],headerFields[3]));
}
lineEmpNrs.Sort(delegate(taMibMsftEmpDetails a, taMibMsftEmpDetails a)
{
return a.EmployeeId.CompareTo(a.EmployeeId);
});
If you can get to at least .Net 3.5 (still uses .Net 2.0 runtime), it gets that much simpler:
public static string ReadLines(StreamReader input)
{
string line;
while ( (line = input.ReadLine()) != null)
yield return line;
}
var lineEmpNrs = ReadLines(HeaderFile)
.Select(l => l.Split(','))
.Select(l => new taMibMsftEmpDetails()
{
EmployeeId = l[1],
EmployeeName = l[2],
ExpenseDate = l[3]
})
.OrderBy(l=> l.EmployeeId)
.ToList();