-->
In general, numerical data arranged in an array-like structure in Python can be converted to arrays through the use of the array function. The most obvious examples are lists and tuples. See the documentation for array for details for its use. Some objects may support the array-protocol and allow conversion to arrays this way.
You can store multiple variables of the same type in an array data structure. You declare an array by specifying the type of its elements. If you want the array to store elements of any type, you can specify
object
as its type. In the unified type system of C#, all types, predefined and user-defined, reference types and value types, inherit directly or indirectly from Object.Example
Int Array To Integer Array
The following example creates single-dimensional, multidimensional, and jagged arrays:
Array overview
An array has the following properties:
- An array can be Single-Dimensional, Multidimensional or Jagged.
- The number of dimensions and the length of each dimension are established when the array instance is created. These values can't be changed during the lifetime of the instance.
- The default values of numeric array elements are set to zero, and reference elements are set to null.
- A jagged array is an array of arrays, and therefore its elements are reference types and are initialized to
null
. - Arrays are zero indexed: an array with
n
elements is indexed from0
ton-1
. - Array elements can be of any type, including an array type.
- Array types are reference types derived from the abstract base type Array. Since this type implements IEnumerable and IEnumerable<T>, you can use foreach iteration on all arrays in C#.
Related sections
C# language specification
For more information, see the C# Language Specification. The language specification is the definitive source for C# syntax and usage.