1

I have an n x n array of size 420 and I want to copy the content of this array into another array of size 20 x 20

I have already tried the following code where smallarray is of 20x20 size and largearray is of 420x420 size.

I am programming in C#, so it is giving me exception as "index out of bound"

for(int i=0;i<20;i++)
   {
     for(int j=0;j<20;i++)
     smallarray[i][j]=largearray[i][j]
   }
1
  • Your array may not be initialized correctly. What class is it? Commented Feb 12, 2017 at 16:07

2 Answers 2

2

Looks like, there is a problem in third line.
Probably it's just a typo. for(int j=0;j<20;i++)
You increments i in both loops. Replace i++ with j++ in second loop and it will work fine.

Sign up to request clarification or add additional context in comments.

Comments

0

try following this syntax

        int[,] largearray = new int[420, 420];
        int[,] smallarray = new int[20, 20];

        // your code for arrays initialization
        // ...

        for (int i = 0; i < 20; i++)
            for (int k = 0; k < 20; k++)
                smallarray[i, k] = largearray[i, k];

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.