Sat 19 Jul 2008
Redimension An Array CSharp
Posted by admin under CSharp Commands |
Here is a function to redimension an array in csharp:-
private static void ReDim(ref TextBox[] arr, int length) { try { if (arr == null) { arr = new TextBox[length]; } else { if (arr.Length != length) { TextBox[] arrTemp = new TextBox[length]; if (length > arr.Length) { Array.Copy(arr, 0, arrTemp, 0, arr.Length); arr = arrTemp; } else { Array.Copy(arr, 0, arrTemp, 0, length); arr = arrTemp; } } } } catch (Exception ex) { string x = ex.ToString(); //Console.WriteLine(x); } }
This example is for a string array but you can overload it with whatever type you want.
No Responses to “ Redimension An Array CSharp ”
Comments:
Leave a Reply
You must be logged in to post a comment.