i setup array , create method return array elements in reverse. e.g. if there 10 slots array1[9] = 6
array2[0] = 6
.
suppose have return array - how that?
and dont know how reverse , add array.
thank you!
int[] arr = {43, 22, 1, 44, 90, 38, 55, 32, 31, 9}; console.writeline("before"); printarray(arr); console.writeline("after"); reverse(arr); console.readkey(true); } static int[] reverse(int[] array) { (int = array.length; < 1; i--) { int x = 0; array[i] = array[x++]; console.writeline(array[i]); } } static void printarray(int[] array) { (int j = 0; j < array.length; j++) { console.write(array[j] + " "); } console.writeline("");
you can use array.reverse
example above line
public static void main() { // creates , initializes new array. array myarray=array.createinstance( typeof(string), 9 ); myarray.setvalue( "the", 0 ); myarray.setvalue( "quick", 1 ); myarray.setvalue( "brown", 2 ); myarray.setvalue( "fox", 3 ); myarray.setvalue( "jumps", 4 ); myarray.setvalue( "over", 5 ); myarray.setvalue( "the", 6 ); myarray.setvalue( "lazy", 7 ); myarray.setvalue( "dog", 8 ); // displays values of array. console.writeline( "the array contains following values:" ); printindexandvalues( myarray ); // reverses sort of values of array. array.reverse( myarray ); // displays values of array. console.writeline( "after reversing:" ); printindexandvalues( myarray ); } public static void printindexandvalues( array myarray ) { ( int = myarray.getlowerbound(0); <= myarray.getupperbound(0); i++ ) console.writeline( "\t[{0}]:\t{1}", i, myarray.getvalue( ) ); }