Often with string[], int[] These arrays, today by chance found another System.Array class, which declares the following:
The code is as follows |
Copy Code |
Public abstract class Array:icloneable, IList, ICollection, IEnumerable, IStructuralComparable, istructuralequatable |
It seems to be an abstract class.
Check out the MSDN and find out what it does for the following purposes:
"Provides methods for creating, manipulating, searching, and sorting arrays, and thus serves as the base class for all arrays in the common language runtime. "
The array class is the base class for language implementations that support arrays. However, only systems and compilers can derive explicitly from the Array class. The user should use the array constructs provided by the language. "
Write your own code to try, indeed, as mentioned above, cannot inherit array this abstract class,
Examples of how array is used:
code is as follows |
copy code |
Array ABC = array.createinstance (typeof (String), 3); ABC. SetValue ("Lzd1", 0); ABC. SetValue ("Lzd2", 1); ABC. SetValue ("Lzd3", 2); for (int i = 0; i < ABC. Length; i++) { Console.WriteLine (ABC. GetValue (i)); } |
Look at this code, feel and string[], int[] The essence is the same, is cumbersome, no wonder MSDN said it is the base class of all arrays, but with refactor translation of a paragraph string[],int[] code, found not translated into an array, Do not know how the interior of the conversion between them, regardless of this, anyway, the most important to think about the role and use of the array where? After all, directly defined arrays are much simpler than array.createinstance ().
Try to understand that a directly defined array does not support sorting, and if you define string[], int[, and you want to sort, you can use the Sort method in the array abstract class, which I think is very useful.
The code is as follows |
Copy Code |
string[] def = new string[] {"Lzd7", "Lzd5", "Lzd6"}; for (int i = 0; i < def. Length; i++) { Console.WriteLine (Def[i]); } Array.Sort (Def); for (int i = 0; i < def. Length; i++) { Console.WriteLine (Def[i]); } |