creating dynamic array
-
i notice that in c# or c++, we normally indicate the size of an array. string[] strArray = new string[5]; strArray[0] = "Ronnie"; strArray[1] = "Jack"; strArray[2] = "Lori"; strArray[3] = "Max"; strArray[4] = "Tricky"; Another way is like this: string[] strArray = new string[] {"Ronnie", "Jack", "Lori", "Max", "Tricky"}; Both have fixed size. is there a way to create an array which can store unlimited amount of data? I know of ArrayList but it is not available in compact framework.
-
i notice that in c# or c++, we normally indicate the size of an array. string[] strArray = new string[5]; strArray[0] = "Ronnie"; strArray[1] = "Jack"; strArray[2] = "Lori"; strArray[3] = "Max"; strArray[4] = "Tricky"; Another way is like this: string[] strArray = new string[] {"Ronnie", "Jack", "Lori", "Max", "Tricky"}; Both have fixed size. is there a way to create an array which can store unlimited amount of data? I know of ArrayList but it is not available in compact framework.
-
okay my bad. arraylist is available in compact framework. however, im gonna try your suggestion instead. List looks like a better choice =)
-
okay my bad. arraylist is available in compact framework. however, im gonna try your suggestion instead. List looks like a better choice =)
Arrays in the .NET CLR are not resizable. Once they are created, that's it. In order to change their size, you'd have to create a new array of the required size, copy the data over, then destroy the original array.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008
But no longer in 2009... -
Arrays in the .NET CLR are not resizable. Once they are created, that's it. In order to change their size, you'd have to create a new array of the required size, copy the data over, then destroy the original array.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008
But no longer in 2009...tks Dave. =)
-
Arrays in the .NET CLR are not resizable. Once they are created, that's it. In order to change their size, you'd have to create a new array of the required size, copy the data over, then destroy the original array.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008
But no longer in 2009... -
There is something called Redim which used to resize the array at later stage, or the best you can do is go for arraylist
C# doesn't have a ReDim method like VB.NET does. And, in VB.NET ReDim does NOT resize an array. Behind the scenes it has to do the exact same thing you'd do manually. It creates a new array of the required size, copies the data to it, then destroys the original array.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008
But no longer in 2009... -
C# doesn't have a ReDim method like VB.NET does. And, in VB.NET ReDim does NOT resize an array. Behind the scenes it has to do the exact same thing you'd do manually. It creates a new array of the required size, copies the data to it, then destroys the original array.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008
But no longer in 2009...Actually, all .NET languages have access to the static "System.Array.Resize" method (since .NET Framework 2, I believe) - but as you said, there's no magic - it just does the same copying that VB's ReDim does.
David Anton Convert between VB, C#, C++, & Java www.tangiblesoftwaresolutions.com
-
Actually, all .NET languages have access to the static "System.Array.Resize" method (since .NET Framework 2, I believe) - but as you said, there's no magic - it just does the same copying that VB's ReDim does.
David Anton Convert between VB, C#, C++, & Java www.tangiblesoftwaresolutions.com
Yeah, I was saying that C# didn't have an equiv keyword to VB.NET's ReDim.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008
But no longer in 2009...