CSharp examples for Language Basics:Array
Create array, loop through array, sort array
using System;/*from w ww . j a v a 2 s .com*/ public class ArrayTest { public static void Main( ) { int[] arr = new int[5]; for( int i = arr.GetLowerBound(0); i <= arr.GetUpperBound(0); i++) arr[i] = i+1; for( int j = arr.GetLowerBound(0); j <= arr.GetUpperBound(0); j++) Console.WriteLine("arr[{0}] = {1}", j, arr[j]); int[] arr2 = new int[] { 25, 10, 4, 7, 15, 2, 1 }; System.Array.Sort( arr2 ); for( int k = arr2.GetLowerBound(0); k <= arr2.GetUpperBound(0); k++) { Console.WriteLine("arr2[{0}] = {1}", k, arr2[k] ); } } }