Private void button8_click (Object sender, eventargs e) <br/>{< br/> double [] [] ptarr = new double [4] []; // array is the reference type. <br/> for (INT I = 0; I <4; I ++) <br/>{< br/> ptarr [I] = new double [3]; <br/>}< br/> ptarr [0] [0] = 0; <br/> ptarr [0] [1] = 1; <br/> ptarr [0] [2] = 2; <br/> double [] d1 = new double [3]; <br/> d1 = ptarr [0]; <br/> // change the value of ptarr again <br/> ptarr [0] [0] = 100; <br/> ptarr [0] [1] = 200; <br/> PTA Rr [0] [2] = 300; <br/> double [] D2 = new double [3]; <br/> D2 = ptarr [0]; <br/> string strres1 = NULL; <br/> string strres2 = NULL; <br/> string strtmp = NULL; <br/> for (INT I = 0; I <3; I ++) <br/>{< br/> strtmp = convert. tostring (d1 [I]); <br/> strres1 + = strtmp; <br/> strres1 + = ','; <br/>}< br/> for (INT I = 0; I <3; I ++) <br/>{< br/> strtmp = convert. tostring (D2 [I]); <br/> strres2 + = strtm P; <br/> strres2 + = ','; <br/>}< br/> MessageBox. show (strres1 + '/N' + strres2); <br/> // The result shows that the values of D1 and D2 are equal! </P> <p> // --> <br/> // The array is of reference type (see the figure below ), therefore, the changes in the ptarr value in the above Code will affect the D1 value (d1 = ptarr [0]). <br/> // Therefore, the output result is 100,200,300 <br/>}< br/>}
// If you want to get the correct result (that is, the values of D1 and D2 are different), use the following code (using the copyto () function of the array)
Double [] [] ptarr = new double [4] []; <br/> for (INT I = 0; I <4; I ++) <br/>{< br/> ptarr [I] = new double [3]; <br/>}< br/> ptarr [0] [0] = 0; <br/> ptarr [0] [1] = 1; <br/> ptarr [0] [2] = 2; <br/> double [] d1 = new double [3]; <br/> // d1 = ptarr [0]; <br/> ptarr [0]. copyto (D1, 0); <br/> // reset the value of ptarr <br/> ptarr [0] [0] = 100; <br/> ptarr [0] [1] = 200; <br/> ptarr [0] [2] = 300; <br/> double [] D2 = new double [3]; <br/> // D2 = ptarr [0]; <br/> ptarr [0]. copyto (D2, 0); <br/> string strres1 = NULL; <br/> string strres2 = NULL; <br/> string strtmp = NULL; <br/> for (INT I = 0; I <3; I ++) <br/>{< br/> strtmp = convert. tostring (d1 [I]); <br/> strres1 + = strtmp; <br/> strres1 + = ','; <br/>}< br/> for (INT I = 0; I <3; I ++) <br/>{< br/> strtmp = convert. tostring (D2 [I]); <br/> strres2 + = strtmp; <br/> strres2 + = ','; <br/>}< br/> MessageBox. show (strres1 + '/N' + strres2 );