Monday, May 24, 2010

C# question - Does the language provide any sort of expandable array?

I created my own class to do this, and it's working well enough, but I suspect that this is not really the "proper" way to do it.


I've done some Google searches for them, but you know what a pain it can be to wade through the various programming forums and whatnot that it links you to.

C# question - Does the language provide any sort of expandable array?
You should design in the bounds and limits. Otherwise, your program's array could grow to the maximum size and cause unwanted results.





Every program should be designed with limits, bounds and a user identifiable error condition and message. Otherwise, you will have CRAPPY software like that stuff that Microsoft sells.





Good luck and Happy Computing!
Reply:hey man if you found a way to make it work stick with it.if its not broke dont fix it.ok thats kind of cliche but i think that applies to this situation.
Reply:Look at the System.Collections.ArrayList - it is a collection class with a .ToArray() method. You can cast it to an array at the very last minute, after you've filled it with the items you want.





Using this method, you don't even have to think about the array depth or boundaries. The .ToArray() method takes care of all of it.
Reply:I'm not sure what you're asking, but you can always declare a dynamic array and expand it as needed:





int[] myarray = new int[];


No comments:

Post a Comment