Interesting ... Microsoft Implements ArrayList as internal array of object
references to your value or referene types. As ArrayList maintains references
so removeat(5) means that object reference will be done null and that
particular element is finalized and references are refreshed that is
arraylist[i] references to arraylist[i+1]. Its very easy to do if array is
object array ... but if you are creating an array of like int or string (any
value type ) then its very tedious.
[quoted text, click to view] "None" wrote:
> Hi,
>
> I have declared array as Int[] ids = new int[50];
>
> In ArrayList we can remove specified index using RemoveAt(5)
> method. My question is how can we do this one with int array (single
> dimensional array) or else is there any alternative solution for this?
>
> If anybody knows the solution pls let me know.
>
> Thanks and Regards,
> Vinothkumar B
> bvinoth@tvsinfotech.com
>
You can't remove an item from an array you could say set the position to
null for an array of a reference type .. Arrays are a fixed size data
structure ..
when you define an array of int [50] think about it creating 50 ints one
after another .. the array points to the first 1 ... so array[22] points to
the memory address of array[0] + 22 * size of your data. In order to remove
an index you would have to recreate the array
Cheers,
Greg Young
MVP - C#
[quoted text, click to view] "None" <vinkumrect@gmail.com> wrote in message
news:1147239731.443447.169190@u72g2000cwu.googlegroups.com...
> Hi,
>
> I have declared array as Int[] ids = new int[50];
>
> In ArrayList we can remove specified index using RemoveAt(5)
> method. My question is how can we do this one with int array (single
> dimensional array) or else is there any alternative solution for this?
>
> If anybody knows the solution pls let me know.
>
> Thanks and Regards,
> Vinothkumar B
> bvinoth@tvsinfotech.com
>
[quoted text, click to view] "None" <vinkumrect@gmail.com> wrote in message
news:1147239731.443447.169190@u72g2000cwu.googlegroups.com...
> Hi,
>
> I have declared array as Int[] ids = new int[50];
>
> In ArrayList we can remove specified index using RemoveAt(5)
> method. My question is how can we do this one with int array (single
> dimensional array) or else is there any alternative solution for this?
If arrays could do everything ArrayList does then there would be no need for
ArrayList.
Removing stuff from an array is never going to be efficient however you do
it so just use ArrayList and ArrayList.ToArray