>>> public static string[,] lines = new string[1,13]; >>> static T[,] ResizeArray<T>(T[,] original, int rows, int cols) >>> { >>> var newArray = new T[rows, cols]; >>> int minRows = Math.Min(rows, original.GetLength(0)); >>> int minCols = Math.Min(cols, original.GetLength(1)); >>> for (int i = 0; i < minRows; i++) >>> for (int j = 0; j < minCols; j++) >>> newArray[i, j] = original[i, j]; >>> return newArray; >>> } >>> public static void loadUploadedInvoices(string filename) >>> { >>> var work = File.ReadAllLines(filename).Select(a => a.Split("\t"[0])).ToArray(); >>> int rows = work.Length-1; >>> string[,] work2 = new string[rows, 13]; >>> for (int r=0; r<rows; r++) >>> for (int c= 0; c<13; c++) >>> { >>> work2[r, c] = work[r][ c]; >>> } >>> lines = AigFundedInvoices.ResizeArray<String>(work2, rows, 13); >>> } >>>>>>
string[,] lines2 = (string[,]) work2.Clone();But can I ask what you subsequently do with the array ?
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