Tuesday, May 3, 2011

C# Arrays

class ArrayList
{
    static void Main()
    {
        // Declare a single-dimensional array 
        int[] array1 = new int[5];

        // Declare and set array element values
        int[] array2 = new int[] { 1, 3, 5, 7, 9 };

        // Alternative syntax
        int[] array3 = { 1, 2, 3, 4, 5, 6 };

        // Declare a two dimensional array
        int[,] multiDimensionalArray1 = new int[2, 3];

        // Declare and set array element values
        int[,] multiDimensionalArray2 = { { 1, 2, 3 }, { 4, 5, 6 } };

        // Declare a jagged array
        int[][] jaggedArray = new int[6][];

        // Set the values of the first array in the jagged array structure
        jaggedArray[0] = new int[4] { 1, 2, 3, 4 };
    }
}

No comments:

Post a Comment

Thank you for Commenting Will reply soon ......

Featured Posts

Enhancing Unix Proficiency: A Deeper Look at the 'Sleep' Command and Signals

Hashtags: #Unix #SleepCommand #Signals #UnixTutorial #ProcessManagement In the world of Unix commands, there are often tools that, at first ...