static void Main(string[] args) { MyArray app = new MyArray(); int [] balance = new int[] { 1000, 2, 3, 17, 50 }; double avg; avg = app.getAverage(balance, 5); Console.WriteLine("平均值:{0}", avg); }
static void Main(string[] args) { MyArray app = new MyArray(); int[] b1 = new int[] { 1, 2, 3, 4, 5 }; double avg; avg = app.getAverage(b1, b1.Length); Console.WriteLine("平均值:{0}", avg); Console.ReadLine(); }
static void Main(string[] args) { MyArray app = new MyArray(); /* an int array with 5 elements */ int[] balance = new int[] { 1000, 2, 3, 17, 50 }; double avg; /* pass pointer to the array as an argument */ avg = app.getAverage(balance, 5); /* output the returned value */ Console.WriteLine("Average value is: {0} ", avg); }
static void Main(string[] args) { MyArray test = new MyArray(); /* an int array with 5 elements */ int[] numbers = new int[] { 1000, 2, 3, 17, 50 }; int finalsum; /* pass pointer to the array as an argument */ finalsum = test.getSum(numbers, numbers.Length); /* output the returned value */ Console.WriteLine("Sum value is: {0} ", finalsum); Console.ReadKey(); }
static void Main(string[] args) { /* Declare Variables */ MyArray app = new MyArray(); int[] n = new int[10]; int i,j; /* Initialise array elements */ for (i = 0; i < 10; i++) { n[i] = i + 100; } /* Write out array variables with for loop */ for (j = 0; j < 10; j++) { Console.WriteLine("Element[{0}] = {1}", j, n[j]); } Console.WriteLine(); /* Write out array variables with foreach loop*/ foreach (int k in n) { int m = k - 100; Console.WriteLine("Element[{0}] = {1}", m, k); } Console.WriteLine(); /* String Array*/ string[] names; /* 2 Dimension arrays*/ int [,] a = new int[3,4] { {0, 1, 2, 3}, {4, 5, 6, 7}, {8, 9, 10, 11} }; /* OUtput 2 Dimension Array */ for (int r = 0; r < 3; r++){ for (int c = 0; c < 4; c++) { Console.WriteLine("a[{0},{1}] = {2}", r, c, a[r,c]); } } Console.WriteLine(); /* Jaggered Array */ int[][] jagArr = new int[][] { new int[] { 0, 0 }, new int[] { 1, 2 }, new int[] { 2, 4 }, new int[] { 3, 6 }, new int[] { 4, 8 } }; /* output each array element's value */ for (int icnt = 0; icnt < 5; icnt++) { for (int jcnt = 0; jcnt < 2; jcnt++) { Console.WriteLine("a[{0}][{1}] = {2}", icnt, jcnt, jagArr[icnt][jcnt]); } } Console.WriteLine(); /* Passing Arrays as funcxtion objects */ int[] balance = new int[] { 1000, 2, 3, 17, 50 }; double avg = app.getAverage(balance, 5); Console.WriteLine("Average value is: {0} ", avg); /* Param Arrays*/ int summation = app.AddElements(512, 720, 250, 567, 889); Console.WriteLine("The sum is: {0}", summation); /* Array MEthods */ app.ArrayMethods(); Console.ReadKey(); }
static void Main(string[] args) { /* Declare Variables */ MyArray app = new MyArray(); int[] n = new int[10]; int i, j; /* Initialise array elements */ for (i = 0; i < 10; i++) { n[i] = i + 100; } /* Write out array variables with for loop */ for (j = 0; j < 10; j++) { Console.WriteLine("Element[{0}] = {1}", j, n[j]); } Console.WriteLine(); /* Write out array variables with foreach loop*/ foreach (int k in n) { int m = k - 100; Console.WriteLine("Element[{0}] = {1}", m, k); } Console.WriteLine(); /* String Array*/ string[] names; /* 2 Dimension arrays*/ int [,] a = new int[3, 4] { { 0, 1, 2, 3 }, { 4, 5, 6, 7 }, { 8, 9, 10, 11 } }; /* OUtput 2 Dimension Array */ for (int r = 0; r < 3; r++) { for (int c = 0; c < 4; c++) { Console.WriteLine("a[{0},{1}] = {2}", r, c, a[r, c]); } } Console.WriteLine(); /* Jaggered Array */ int[][] jagArr = new int[][] { new int[] { 0, 0 }, new int[] { 1, 2 }, new int[] { 2, 4 }, new int[] { 3, 6 }, new int[] { 4, 8 } }; /* output each array element's value */ for (int icnt = 0; icnt < 5; icnt++) { for (int jcnt = 0; jcnt < 2; jcnt++) { Console.WriteLine("a[{0}][{1}] = {2}", icnt, jcnt, jagArr[icnt][jcnt]); } } Console.WriteLine(); /* Passing Arrays as funcxtion objects */ int[] balance = new int[] { 1000, 2, 3, 17, 50 }; double avg = app.getAverage(balance, 5); Console.WriteLine("Average value is: {0} ", avg); /* Param Arrays*/ int summation = app.AddElements(512, 720, 250, 567, 889); Console.WriteLine("The sum is: {0}", summation); /* Array MEthods */ app.ArrayMethods(); Console.ReadKey(); }