Skip to Main Content
C# in a Nutshell, Second Edition
book

C# in a Nutshell, Second Edition

by Peter Drayton, Ben Albahari, Ted Neward
August 2003
Intermediate to advanced content levelIntermediate to advanced
928 pages
32h 1m
English
O'Reilly Media, Inc.
Content preview from C# in a Nutshell, Second Edition

Name

Array

Synopsis

Unlike other environments (such as C++), .NET has arrays of first-class type, in that all array types are derivatives of the base type Array. All methods are available on any array type, regardless of its declaration. In fact, the CLR is required to synthesize a pseudotype that matches the declaration. Thus, when you declare a variable of type string[ ], the CLR creates an anonymous type, deriving from Array specifically for storing Strings in a one-dimensional array.

The Array class has a number of useful array-related methods, such as checking for bounds violations (attempting to access an element of the array that isn’t in the array’s declared size) and retrieval of array length. In addition, because Array also implements the ICloneable, System.Collections.IList, System.Collections.ICollection, and System.Collections.IEnumerable interfaces, arrays can be used anywhere these interface types are expected.

Starting with .NET 1.1, Array now has support for 64-bit indexer values, meaning that an array can stretch to include 264 possible elements. As a result, several methods, including Copy( ), GetValue( ), and SetValue( ), among others, take Int64 parameters as well as Int32.

Arrays are reference types. This means that the statement ArrayB = ArrayA results in two objects that reference the same array. Use ArrayB = ArrayA.Clone( ) to create a duplicate copy of an array. This will be a shallow copy with identical references to subobjects. To create a deep copy in which ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

C# in a Nutshell

C# in a Nutshell

Ben Albahari, Ted Neward, Peter Drayton
C# 7.0 in a Nutshell

C# 7.0 in a Nutshell

Joseph Albahari, Ben Albahari
C# Cookbook, 2nd Edition

C# Cookbook, 2nd Edition

Jay Hilyard, Stephen Teilhet
C# Cookbook

C# Cookbook

Stephen Teilhet, Jay Hilyard

Publisher Resources

ISBN: 0596005261Catalog PageErrata