| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Array ClassProvides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the base class for all arrays in the common language runtime.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Visibility | Name | Parameters | Return Type |
|---|---|---|---|
| public static | AsReadOnly | ( T array ) | ReadOnlyCollection`1 |
| public static | BinarySearch | ( Array array , Object value , IComparer comparer ) | Int32 |
| public static | BinarySearch | ( T array , Int32 index , Int32 length , T value , IComparer`1 comparer ) | Int32 |
| public static | BinarySearch | ( Array array , Object value ) | Int32 |
| public static | BinarySearch | ( Array array , Int32 index , Int32 length , Object value ) | Int32 |
| public static | BinarySearch | ( T array , T value ) | Int32 |
| public static | BinarySearch | ( Array array , Int32 index , Int32 length , Object value , IComparer comparer ) | Int32 |
| public static | BinarySearch | ( T array , T value , IComparer`1 comparer ) | Int32 |
| public static | BinarySearch | ( T array , Int32 index , Int32 length , T value ) | Int32 |
| public static | Clear | ( Array array , Int32 index , Int32 length ) | Void |
| public | Clone | ( ) | Object |
| public static | ConstrainedCopy | ( Array sourceArray , Int32 sourceIndex , Array destinationArray , Int32 destinationIndex , Int32 length ) | Void |
| public static | ConvertAll | ( TInput array , Converter`2 converter ) | TOutput |
| public static | Copy | ( Array sourceArray , Array destinationArray , Int32 length ) | Void |
| public static | Copy | ( Array sourceArray , Array destinationArray , Int64 length ) | Void |
| public static | Copy | ( Array sourceArray , Int64 sourceIndex , Array destinationArray , Int64 destinationIndex , Int64 length ) | Void |
| public static | Copy | ( Array sourceArray , Int32 sourceIndex , Array destinationArray , Int32 destinationIndex , Int32 length ) | Void |
| public | CopyTo | ( Array array , Int32 index ) | Void |
| public | CopyTo | ( Array array , Int64 index ) | Void |
| public static | CreateInstance | ( Type elementType , Int32 length1 , Int32 length2 ) | Array |
| public static | CreateInstance | ( Type elementType , Int32 length1 , Int32 length2 , Int32 length3 ) | Array |
| public static | CreateInstance | ( Type elementType , Int32 lengths ) | Array |
| public static | CreateInstance | ( Type elementType , Int32 lengths , Int32 lowerBounds ) | Array |
| public static | CreateInstance | ( Type elementType , Int32 length ) | Array |
| public static | CreateInstance | ( Type elementType , Int64 lengths ) | Array |
| public static | Exists | ( T array , Predicate`1 match ) | Boolean |
| public static | Find | ( T array , Predicate`1 match ) | T |
| public static | FindAll | ( T array , Predicate`1 match ) | T |
| public static | FindIndex | ( T array , Int32 startIndex , Int32 count , Predicate`1 match ) | Int32 |
| public static | FindIndex | ( T array , Predicate`1 match ) | Int32 |
| public static | FindIndex | ( T array , Int32 startIndex , Predicate`1 match ) | Int32 |
| public static | FindLast | ( T array , Predicate`1 match ) | T |
| public static | FindLastIndex | ( T array , Int32 startIndex , Int32 count , Predicate`1 match ) | Int32 |
| public static | FindLastIndex | ( T array , Predicate`1 match ) | Int32 |
| public static | FindLastIndex | ( T array , Int32 startIndex , Predicate`1 match ) | Int32 |
| public static | ForEach | ( T array , Action`1 action ) | Void |
| public | GetEnumerator | ( ) | IEnumerator |
| public | GetLength | ( Int32 dimension ) | Int32 |
| public | GetLongLength | ( Int32 dimension ) | Int64 |
| public | GetLowerBound | ( Int32 dimension ) | Int32 |
| public | GetUpperBound | ( Int32 dimension ) | Int32 |
| public | GetValue | ( Int64 index1 , Int64 index2 , Int64 index3 ) | Object |
| public | GetValue | ( Int64 indices ) | Object |
| public | GetValue | ( Int32 index ) | Object |
| public | GetValue | ( Int32 index1 , Int32 index2 ) | Object |
| public | GetValue | ( Int32 indices ) | Object |
| public | GetValue | ( Int32 index1 , Int32 index2 , Int32 index3 ) | Object |
| public | GetValue | ( Int64 index1 , Int64 index2 ) | Object |
| public | GetValue | ( Int64 index ) | Object |
| public static | IndexOf | ( T array , T value ) | Int32 |
| public static | IndexOf | ( Array array , Object value , Int32 startIndex , Int32 count ) | Int32 |
| public static | IndexOf | ( Array array , Object value , Int32 startIndex ) | Int32 |
| public static | IndexOf | ( Array array , Object value ) | Int32 |
| public static | IndexOf | ( T array , T value , Int32 startIndex , Int32 count ) | Int32 |
| public static | IndexOf | ( T array , T value , Int32 startIndex ) | Int32 |
| public | Initialize | ( ) | Void |
| public static | LastIndexOf | ( T array , T value ) | Int32 |
| public static | LastIndexOf | ( T array , T value , Int32 startIndex ) | Int32 |
| public static | LastIndexOf | ( T array , T value , Int32 startIndex , Int32 count ) | Int32 |
| public static | LastIndexOf | ( Array array , Object value ) | Int32 |
| public static | LastIndexOf | ( Array array , Object value , Int32 startIndex ) | Int32 |
| public static | LastIndexOf | ( Array array , Object value , Int32 startIndex , Int32 count ) | Int32 |
| public static | Resize | ( T[]& array , Int32 newSize ) | Void |
| public static | Reverse | ( Array array ) | Void |
| public static | Reverse | ( Array array , Int32 index , Int32 length ) | Void |
| public | SetValue | ( Object value , Int64 index1 , Int64 index2 , Int64 index3 ) | Void |
| public | SetValue | ( Object value , Int32 index1 , Int32 index2 ) | Void |
| public | SetValue | ( Object value , Int32 index ) | Void |
| public | SetValue | ( Object value , Int64 index ) | Void |
| public | SetValue | ( Object value , Int64 index1 , Int64 index2 ) | Void |
| public | SetValue | ( Object value , Int64 indices ) | Void |
| public | SetValue | ( Object value , Int32 indices ) | Void |
| public | SetValue | ( Object value , Int32 index1 , Int32 index2 , Int32 index3 ) | Void |
| public static | Sort | ( Array keys , Array items ) | Void |
| public static | Sort | ( Array array ) | Void |
| public static | Sort | ( Array keys , Array items , Int32 index , Int32 length ) | Void |
| public static | Sort | ( Array keys , Array items , Int32 index , Int32 length , IComparer comparer ) | Void |
| public static | Sort | ( Array keys , Array items , IComparer comparer ) | Void |
| public static | Sort | ( Array array , Int32 index , Int32 length , IComparer comparer ) | Void |
| public static | Sort | ( Array array , Int32 index , Int32 length ) | Void |
| public static | Sort | ( Array array , IComparer comparer ) | Void |
| public static | Sort | ( TKey keys , TValue items , Int32 index , Int32 length ) | Void |
| public static | Sort | ( TKey keys , TValue items , IComparer`1 comparer ) | Void |
| public static | Sort | ( T array , Int32 index , Int32 length ) | Void |
| public static | Sort | ( TKey keys , TValue items ) | Void |
| public static | Sort | ( T array ) | Void |
| public static | Sort | ( T array , Comparison`1 comparison ) | Void |
| public static | Sort | ( T array , IComparer`1 comparer ) | Void |
| public static | Sort | ( T array , Int32 index , Int32 length , IComparer`1 comparer ) | Void |
| public static | Sort | ( TKey keys , TValue items , Int32 index , Int32 length , IComparer`1 comparer ) | Void |
| public static | TrueForAll | ( T array , Predicate`1 match ) | Boolean |
The Array class is the base class for language implementations that support arrays. However, only the system and compilers can derive explicitly from the Array class. Users should use the array constructs provided by the language.
An element is a value in an Array. The length of an Array is the total number of elements it can contain. The rank of an Array is the number of dimensions in the Array. The lower bound of a dimension of an Array is the starting index of that dimension of the Array; a multidimensional Array can have different bounds for each dimension.
Type objects provide information about array type declarations. Array objects with the same array type share the same Type object.
Type.IsArray and Type.GetElementType might not return the expected results with Array because if an array is cast to the type Array, the result is an object, not an array. That is, typeof ( System.Array ).IsArray returns false, and typeof ( System.Array ).GetElementType returns a null reference ( Nothing in Visual Basic ).
Unlike most classes, Array provides the CreateInstance method, instead of public constructors, to allow for late bound access.
The Array.Copy method copies elements not only between arrays of the same type but also between standard arrays of different types; it handles type casting automatically.
The following example creates and initializes an Array and displays its properties and its elements.
public static void createArray ( ) {
// creates and initializes a new three-dimensional Array of type Int32.
Array myArr = Array.CreateInstance ( typeof ( Int32 ), 2, 3, 4 );
for ( int i = myArr.GetLowerBound ( 0 ); i <= myArr.GetUpperBound ( 0 ); i++ ) {
for ( int j = myArr.GetLowerBound ( 1 ); j <= myArr.GetUpperBound ( 1 ); j++ ) {
for ( int k = myArr.GetLowerBound ( 2 ); k <= myArr.GetUpperBound ( 2 ); k++ ) {
myArr.SetValue ( ( i*100 ) + ( j*10 ) +k, i, j, k );
}
}
}
// Displays the properties of the Array.
Response.Write ( "The Array has " + myArr.Rank +
dimension (s) and a total of " + myArr.Length + " elements.",
Response.Write ( " Length Lower Upper" );
for ( int i = 0; i < myArr.Rank; i++ ) {
Response.Write ( l + ": " + myArr.GetLength ( l ) );
Response.Write ( myArr.GetLowerBound ( l ) + " " + myArr.GetUpperBound ( l ) );
}
// displays the contents of the Array.
Response.Write ( "The Array contains the following values:" );
printValues ( myArr );
}
public static void printValues ( Array myArr ) {
System.Collections.IEnumerator myEnumerator = myArr.GetEnumerator ( );
int i = 0;
int cols = myArr.GetLength ( myArr.Rank - 1 );
while ( myEnumerator.MoveNext ( ) ) {
if ( i < cols ) {
i++;
} else {
i = 1;
}
Response.Write ( myEnumerator.Current );
}
}
| |||
| C# | VB | JScript | |
The obove code produces the following output.
The Array has 3 dimension ( s ) and a total of 24 elements. Length Lower Upper 0: 2 0 1 1: 3 0 2 2: 4 0 3 The Array contains the following values: 0 1 2 3 10 11 12 13 20 21 22 23 100 101 102 103 110 111 112 113 120 121 122 123
Check out related books at Amazon
© 2000-2008 Rey Nuñez All rights reserved.
If you have any question, comment or suggestion
about this site, please send us a note
You can help support aspxtreme