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 9148427
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:16:09+00:00 2026-06-17T11:16:09+00:00

This algorithm is about to store strings from Array A to Array B by

  • 0

This algorithm is about to store strings from Array A to Array B by storing “A”, “B” to Index 8 and Index 9
I really initiate to make the array size of B to be 10 because later I will put some other things there.

My partial code:

string[] A = new string[]{"A","B"}
string[] B = new string[10]; 
int count;

for(count = 0; count < A.length; count++)
{
      B[count] = A[count]
}
  • 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-06-17T11:16:10+00:00Added an answer on June 17, 2026 at 11:16 am

    So you want to increment every index with 2:

    string[] A = new string[] { "A", "B", "C", "D" };
    string[] B = new string[A.Length + 2];
    for (int i = 0; i < A.Length; i++)
    {
        B[i + 2] = A[i];
    }
    

    Demo

    Index: 0 Value: 
    Index: 1 Value: 
    Index: 2 Value: A
    Index: 3 Value: B
    Index: 4 Value: C
    Index: 5 Value: D
    

    Edit: So you want to start with index 0 in B and always leave a gap?

    string[] A = new string[] { "A", "B", "C", "D" };
    string[] B = new string[A.Length * 2 + 2]; // you wanted to add something other as well
    for (int i = 0; i/2 < A.Length; i+=2)
    {
        B[i] = A[i / 2];
    }
    

    Demo

    Index: 0 Value: A
    Index: 1 Value: 
    Index: 2 Value: B
    Index: 3 Value: 
    Index: 4 Value: C
    Index: 5 Value: 
    Index: 6 Value: D
    Index: 7 Value: 
    Index: 8 Value: 
    Index: 9 Value:
    

    Update ” Is there any alternative coding aside from this?”

    You can use Linq, although it would be less readable and efficient than a simple loop:

    String[] Bs = Enumerable.Range(0, A.Length * 2 + 2) // since you want two empty places at the end
     .Select((s, i) => i % 2 == 0 && i / 2 < A.Length ? A[i / 2] : null)
     .ToArray();
    

    Final Update according to your last comment(start with index 1 in B):

    for (int i = 1; (i-1) / 2 < A.Length; i += 2)
    {
        B[i] = A[(i-1) / 2];
    }
    

    Demo

    Index: 0 Value: 
    Index: 1 Value: A
    Index: 2 Value: 
    Index: 3 Value: B
    Index: 4 Value: 
    Index: 5 Value: C
    Index: 6 Value: 
    Index: 7 Value: D
    Index: 8 Value: 
    Index: 9 Value
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a question about returning efficiently strings and chars from a string array
This is kind of more generic question, isn't language-specific. More about idea and algorithm
I have this algorithm in Java to store passwords in database. I'd like to
How to make this algorithm better and working, where I am always ending up
I'm trying to implement this algorithm description from a previous question I had here
This question came up when I was thinking about the algorithm to fast compute
I have a homework that asks this: Make an algorithm and pseudocode, which will
While trying to make this merge-sort algorithm with recursive calls, i ended up getting
This is about the analysis of insertion sort in the book 'Introduction to Algorithms'.
I have this algorithm that I want to implement on VB6. Sub Main() dim

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.