public class Invoice > { > public static explicit operator Invoice(string fields) > { > string[] array = fields.Split("\t"[0]).ToArray(); > var inv = new Invoice(); > inv.InvoiceNumber = Convert.ToInt32(array[0]); > inv.InvoiceDate = Convert.ToDateTime(array[1]); > inv.Company = array[2]; > //etc > return inv; > } > public DateTime InvoiceDate { get; set; } > public int InvoiceNumber { get; set; } > public decimal Amount { get; set; } > public string Company { get; set; } > }Your code could then just be:
IEnumerable<Invoice> invoices = File.ReadAllLines(fileName).Select(s => (Invoice)s); >//Do whatever