Provides methods for manipulating arrays.This class is the base class for all arrays. This class cannot be inherited.
public sealed class Array: Object, ICloneable, ICollection, IEnumerable, IList
ObjectArray
Multidimensional arrays are not supported.
// This sample shows how to implement the Array. It also shows some methods that use for the Array.
using System;
using System.Diagnostics;
public class SampleArray
{
static void Main()
{
// Creates and initializes a new integer array and a new object array.
int[] myIntArray = new int[5]{30,25,20,15,10};
object[] myObjectArray = new object[7]{4,5,1,2,3,7,6};
// Displays the integer and object arrays.
Debug.WriteLine(" Before sorting");
Debug.Write("\t Integer array: ");
DisplayArray(myIntArray
);Debug.Write("\n\t Object array: \t");
DisplayArray(myObjectArray);
// Uses the sorting method.
Array.Sort(myIntArray);
Array.Sort(myObjectArray);
// Displays the integer and object arrays.
Debug.Write("\n\n After sorting");
Debug.Write("\n\t Integer array: ");
DisplayArray(myIntArray);
Debug.Write("\n\t Object array: \t");
DisplayArray(myObjectArray);
// Copies myIntArray to myObjectArray starting at third index.
myIntArray.CopyTo(myObjectArray, 2);
// Displays the integer and object arrays.
Debug.Write("\n\n After copying");
Debug.Write("\n\t Integer array: ");
DisplayArray(myIntArray);
Debug.Write("\n\t Object array: \t");
DisplayArray(myObjectArray);
// Reverses the integer array.
Array.Reverse(myIntArray);
Array.Reverse(myObjectArray);
// Displays the integer and object arrays.
Debug.Write("\n\n After reversing");
Debug.Write("\n\t Integer array: ");
DisplayArray(myIntArray);
Debug.Write("\n\t Object array: \t");
DisplayArray(myObjectArray);
}
static void DisplayArray( int[] myArray )
{
for(int i = 0; i < myArray.Length; i++)
{
Debug.Write(myArray[i] + "\t");
}
}
static void DisplayArray( object[] myArray )
{
for(int i = 0; i < myArray.Length; i++)
{
Debug.Write(myArray[i] + "\t");
}
}
}
/*
The output of the sample.
Before sorting
Integer array: 30 25 20 15 10
Object array: 4 5 1 2 3 7 6
After sorting
Integer array: 10 15 20 25 30
Object array: 1 2 3 4 5 6 7
After copying
Integer array: 10 15 20 25 30
Object array: 1 2 10 15 20 25 30
After reversing
Integer array: 30 25 20 15 10
Object array: 30 25 20 15 10 2 1
*/
Namespace System Flash Library corlib.scl Flash Library Version 2.0.0.2466 Silverlight Library System.Windows.Forms.dll
| © 2003-2007 NETiKA Technologies. All rights reserved. |