Creating and Using an Array in C#

Working with Arrays in C# is simpler and less error-prone than C and C++. Arrays in C# are objects that support the properties shown in Table 4-8.

Table 4-8. A sample of the properties in System.Array
Property NameDescription
LengthReturns the number of elements in the array. If the array is multidimensional, it returns the total number of elements in all dimensions.
RankReturns the number of dimensions of the array, that is, the rank will be 2 for a 2D array.

The C# array class contains the methods shown in Table 4-9.

Table 4-9. A sample of the methods in System.Array
Method NameDescription
ClearSets a range of elements in the array to zero or a null reference.
CopyCopies a portion of one array to another (deep copy). ...

Get .NET and COM Interoperability Handbook, The now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.