Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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....

Posted
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.

Posted

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???

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.

Posted
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.

Posted
and now that I think about it, array lists aren't firectly remotable either.

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*
Posted

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

"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
Posted
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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...