Click here to Skip to main content
15,885,027 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i Declared string array as


string[] strArray2 = new string[1];
after adding one by one to string array in VB as

strArray2 = (string[])Utils.CopyArray((Array)strArray2, new string[index + 1]);


how to write that code in c#
Posted
Updated 30-Mar-16 6:37am

In this way:
C#
string[] strArray2 = new string[1];
string[] tmpArray = new string[strArray2.Length + 1];
Array.Copy(strArray2, tmpArray, strArray2.Length);
strArray2 = tmpArray;

Also, you can use this: Array.Resize(ref strArray2, strArray2.Length + 1);

But C# has List<string> class. It's much more simple to add elements to it .
 
Share this answer
 
v2
Comments
Matt T Heffron 31-Mar-16 12:53pm    
This is a 6 year old question! Asking your NEW question here is pretty pointless.
Almost no one will bother to look here.
Delete this and post this as a NEW question: use the red "Ask a Question" button above!
Just for your future reference, there are many sites which convert VB.Net code to C# and vice versa.

One of them is: this[^]
 
Share this answer
 

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