Home > Net >  C # - array as a parameter, to achieve similar to offset the effect of the C language array
C # - array as a parameter, to achieve similar to offset the effect of the C language array

Time:05-25

Such as problem, want to achieve under the C # array as input parameters, implementation is similar to offset the effect of the C language array parameters, the function of main function is to a certain position in the array modifications, the effect of the C code is as follows:
 
# include & lt; Stdio. H>

Void arrayTest (char arr [])
{
Arr [0]=0 xaa;
Arr [1]=0 x55;
}

Int main (int arg c, const char * * argv)
{
Unsigned char arr [10]={0};
Int index=0;

ArrayTest (& amp; Arr [index]);//the address of the first element of the array and enter
for (int i=0; I & lt; 10; I++)
Printf (" % 02 x ", arr [I]);
Putchar (10);

The index +=2;
ArrayTest (& amp; Arr [index]);//array offset after two units into the
for (int i=0; I & lt; 10; I++)
Printf (" % 02 x ", arr [I]);
Putchar (10);

Index +=4;
ArrayTest (& amp; Arr [index]);//array offset after four units into the
for (int i=0; I & lt; 10; I++)
Printf (" % 02 x ", arr [I]);
Putchar (10);

return 0;
}


Output the effect:

AA 55 00 00 00 00 00 00 00 00
AA 55 55 00 00 00 00 00 00 AA
AA 55 55 55 00 00 00 00 AA AA

Excuse me, how to write a function in a c # language environment (including the parameters of the function definition) code to achieve the above
 arrayTest (& amp; Arr [index]); 
the dia use effect??

CodePudding user response:

 
Void arrayTest (byte [] arr, int nIndex)
{
Arr [0 + nIndex]=0 xaa;
Arr (1 + nIndex]=0 x55;
}

  •  Tags:  
  • C#
  • Related