FlyBoy Posted October 3, 2004 Posted October 3, 2004 is there any way to use dynamic arrays in c# except from collections (arraylist...)?? when im trying to perform the following action: int[] ar = new int[] /// Not bounded. i get an error.... Quote
HJB417 Posted October 4, 2004 Posted October 4, 2004 is there any way to use dynamic arrays in c# except from collections (arraylist...)?? when im trying to perform the following action: int[] ar = new int[] /// Not bounded. i get an error.... you need to specify the values of the array if when you initialize it like that e.x.: int[] ar = new int[] {1,2,4,8} //The length of the array will be the # of values entered (4), and will contain the values 1,2,4,8 int[] ar = new int[6]; array with a length of 6, but all the values are zero. dynamic arrays can also be made using Array.CreateInstance. Quote
Joe Mamma Posted October 4, 2004 Posted October 4, 2004 i believe the reason for not allowing a redim of arrays in C# is that they wouldn't be self describing which makes them not remotable. The array needs to be redefined. why do you not want to use the array list??? Quote Joe Mamma Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized. Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.
HJB417 Posted October 4, 2004 Posted October 4, 2004 i believe the reason for not allowing a redim of arrays in C# is that they wouldn't be self describing which makes them not remotable. The array needs to be redefined. why do you not want to use the array list??? If I were to guess, maybe because arraylists aren't strongtyped and .net 2.0 final hasn't been released yet for generics. Quote
Joe Mamma Posted October 4, 2004 Posted October 4, 2004 and now that I think about it, array lists aren't firectly remotable either. Quote Joe Mamma Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized. Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.
*Experts* Nerseus Posted October 4, 2004 *Experts* Posted October 4, 2004 You can VERY easily do a "preserve" yourself, if it's what you need: int[] a = new int[] {1, 2, 3, 4, 5}; int[] b = new int[10]; // the array to preserve "to" a.CopyTo(b, 0); If this is in a function, just return b. If you need the array back in a, just assign a to b: a = b; As a note: Generally, you won't need to preserve an array. If you really need to keep resizing an array, you're probably better off with ArrayList and converting to a true array when you're done (if that's even needed). If you're resizing in a loop, you likely know the size of the array to begin with and you can just set the size of the array once, before getting in the loop. The "Preserve" keyword in VB works like the code posted above. That is, it's *copying* the array every time. If you do this a lot on big arrays, that's a LOT of extra overhead. -ner Quote "I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
HJB417 Posted October 4, 2004 Posted October 4, 2004 and now that I think about it' date=' array lists aren't firectly remotable either.[/quote'] ArrayLists should be remoteable, it has the serializable tag. It would probably fail @ runtime though, if it contains a non-serializable object. Quote
FlyBoy Posted October 5, 2004 Author Posted October 5, 2004 ok i see.....thanks for the help guys. really thanks. at least now i know that im not missing anything Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.