Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Redimensioning an array in c#
Message
From
04/11/2015 13:52:13
 
General information
Forum:
ASP.NET
Category:
Other
Environment versions
Environment:
VB 9.0
OS:
Windows 10
Network:
Windows 2008 Server
Database:
MS SQL Server
Application:
Web
Miscellaneous
Thread ID:
01627021
Message ID:
01627030
Views:
62
Why not use a List instead?


>
>        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);
>        }
>
>
>
>This kinda works, but I'm copying everything twice. Is there a way to do this by copying only once?
Craig Berntson
MCSD, Microsoft .Net MVP, Grape City Community Influencer
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform