woody79
October 31st, 2008, 04:49 AM
How can I add a string to an existing array, but without using an array list?
|
Click to See Complete Forum and Search --> : [RESOLVED] Inserting into an Array but not ArrayList woody79 October 31st, 2008, 04:49 AM How can I add a string to an existing array, but without using an array list? foamy October 31st, 2008, 04:56 AM Create a new array with the appropriate size and add the items from the old array into it. string[] existingarray = { "one", "two", "three" }; foreach (string s in existingarray) Console.Write(s + " "); Console.WriteLine(); string newvalue = "four"; string[] newarray = new string[4]; newarray[0] = existingarray[0]; newarray[1] = existingarray[1]; newarray[2] = existingarray[2]; newarray[3] = newvalue; foreach (string s in newarray) Console.Write(s + " "); Console.WriteLine(); codeguru.com
Copyright Internet.com Inc., All Rights Reserved. |