CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    May 2008
    Location
    .NET2.0 / .NET3.5 > VS2008
    Posts
    18

    [RESOLVED] Inserting into an Array but not ArrayList

    How can I add a string to an existing array, but without using an array list?

  2. #2
    Join Date
    May 2007
    Location
    Denmark
    Posts
    623

    Re: Inserting into an Array but not ArrayList

    Create a new array with the appropriate size and add the items from the old array into it.

    Code:
                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();
    It's not a bug, it's a feature!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured