Click here to Skip to main content
15,890,506 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
What is the similar function in c# like redim preserve which is in VB.

As we are developing .net c# wcf service from existing old VB6 code so as per our situation or condition of existing code.. I can't use System.Array.Copy

Any body hv feasable way...?
Posted
Updated 24-Jun-16 7:15am

As you have discovered, an array in C# is immutable which means that you can't extend it. You can solve your problem in one of the following ways:

1. Use a generic list which grows automatically.
2. Copy your array into a temporary array, create a new instance of the original array at a larger size and copy the values back in.
 
Share this answer
 
Comments
Vishal Sanchihar 1981 11-May-10 5:14am    
As above mentioned in my question..As per the present situation of the project I can no use Array List or generic list. as 90% code already has been developed.
If there is no other solution then I can go for no. 2. Copy Array.

Thanks!
AFAIK, there is no method in c# which imulate redim preserve of VB.
You can use ArrayList instead.
 
Share this answer
 
Comments
Pete O'Hanlon 10-May-10 6:48am    
Why use ArrayList? Unless the OP is using an object, he is much better off using a generic list as this will not require boxing/unboxing.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900