|
-
October 9th, 2014, 12:14 AM
#1
Storing multiple function calls in an array
My function returns an int array with 2 values
Let's say, res[0] and res[1]
When I'm calling the array in a for loop for multiple times, and when I'm storing the results in another array, in each iteration the results are over-written with the new results.
If the first call returns [0,1] the array will store [0,1] at index [0] and [1], which is fine, but when I'm calling the function again, the new results are stored at the same indexes [0] and [1]
How can I avoid that?
Function Code:
Code:
int[] MatrixMul(string subInput, int[,] key)
{
int[] result = new int[subInput.Length];
for (int row = 0; row < key.GetLength(0); row++)
{
for (int col = 0; col < key.GetLength(0); col++)
{
result[row]+= key[row, col] * AtoZ.IndexOf(subInput[col]);
}
}
return result;
}
Calling Code:
Code:
for (int i = 0; i < outPut.Length; i++)
{
encChars = MatrixMul(outPut[i], key);
}
I really need some advice, so I can call my function and store all the values in this array.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|