Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7595589
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T21:42:30+00:00 2026-05-30T21:42:30+00:00

I would like to programmatically add or remove some elements to a string array

  • 0

I would like to programmatically add or remove some elements to a string array in C#, but still keeping the items I had before, a bit like the VB function ReDim Preserve.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T21:42:32+00:00Added an answer on May 30, 2026 at 9:42 pm

    The obvious suggestion would be to use a List<string> instead, which you will have already read from the other answers. This is definitely the best way in a real development scenario.

    Of course, I want to make things more interesting (my day that is), so I will answer your question directly.

    Here are a couple of functions that will Add and Remove elements from a string[]…

    string[] Add(string[] array, string newValue){
        int newLength = array.Length + 1;
    
        string[] result = new string[newLength];
    
        for(int i = 0; i < array.Length; i++)
            result[i] = array[i];
    
        result[newLength -1] = newValue;
    
        return result;
    }
    
    string[] RemoveAt(string[] array, int index){
        int newLength = array.Length - 1;
    
        if(newLength < 1)
        {
            return array;//probably want to do some better logic for removing the last element
        }
    
        //this would also be a good time to check for "index out of bounds" and throw an exception or handle some other way
    
        string[] result = new string[newLength];
        int newCounter = 0;
        for(int i = 0; i < array.Length; i++)
        {
            if(i == index)//it is assumed at this point i will match index once only
            {
                continue;
            }
            result[newCounter] = array[i];
            newCounter++;
        }  
    
        return result;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to add programmatically to LinearLayout some TextViews . And I want
I would like to add 3D or glossy look to some iPhone UIButtons, but
I would like to programmatically Add a UIScrollView in a UIAlertView. I found a
I'm writing a simple VS add-in and would like to programmatically invoke the Document
I would like to programmatically add the shared libraries to my deployed applications in
I would like to programmatically add to Windows a name / IP association so
I would like to programmatically add a custom site template (.stp file) to a
I would like to be able to programmatically add a viewgroup to another viewgroup.
I am generating a webview programmatically I would like to add a button over
I am adding a UIView programmatically to superview, and i would like to add

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.