c# - multiplying each element of one array by all the elements of a second array -


i having difficult time multiplying elements in 2 array's.

    int[] firstarray = { 1,2,3,4 };     int[] secondarray = { 10,20,30,40 }; 

i need multiply first element of "firstarray" each of elements in "secondarray". take second element of "firstarray" each of elements in "secondarray", , on until have multiplied of elements in first array each of elements in second array.

so far have figured out how first element building 3rd array

    int[] thirdarray = [4]      (int counter = 0; counter < thirdarray.length; counter ++)     thirdarray[counter] = firstarray[counter] * secondarray[counter];     console.writeline(thirdarray[counter]); 

this takes elements of first array , directly multiply across second element. should have 16 int results if change thirdarray [16] there out of range exception. if can appreciated.

i believe achieve looking for:

int[] thirdarray = new int[16];  (int = 0; < 4; i++)     (int j = 0; j < 4; j++)         thirdarray[i * 4 + j] = firstarray[i] * secondarray[j]; 

Comments