03.01.2015 Views

Complete set: Intro to C - Bill Buchanan

Complete set: Intro to C - Bill Buchanan

Complete set: Intro to C - Bill Buchanan

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

3 Arrays and Collections<br />

3.1 <strong>Intro</strong>duction<br />

This module covers the key elements of arrays, indexers and collections. It covers:<br />

• Arrays.<br />

• Reading from CSV files.<br />

• System.Collections.<br />

• ArrayLists.<br />

• HashTables.<br />

3.2 Arrays<br />

Simple variables, such as int, float, double and string only hold a single element.<br />

This is fine when we have only a few things <strong>to</strong> s<strong>to</strong>re, but it is difficult <strong>to</strong> process data<br />

elements in a sequential way. Thus, programming languages support arrays which<br />

allow more than one element <strong>to</strong> be s<strong>to</strong>red under a common name, which allows the<br />

elements <strong>to</strong> be indexed.<br />

In C# an array is created from an object of type System.Array, as illustrated in<br />

Figure 3.1. The main methods are:<br />

duction <strong>to</strong> .NET<br />

<strong>Intro</strong><br />

BinarySearch()<br />

Clear()<br />

Clone()<br />

Copy()<br />

CopyTo()<br />

CreateInstance()<br />

GetLength()<br />

IndexOf()<br />

Initialize()<br />

LastIndexOf()<br />

Reverse()<br />

SetValue()<br />

Sort()<br />

Performs a binary on a one‐dimensional array<br />

Sets a range of elements <strong>to</strong> zero, False or NULL.<br />

Make a shallow copy of the array.<br />

Copies a range of values in an array.<br />

Copies one array <strong>to</strong> another.<br />

Create a multidimensional array.<br />

Return the number of elements in the array.<br />

Search for an object, and return the first index value of its place.<br />

Set all the elements in the array <strong>to</strong> their default value.<br />

Returns the last object in the array.<br />

Reverses the array.<br />

Sets a specific array element <strong>to</strong> a value.<br />

Performs a sort on the array.<br />

Agilent .NET Course: Arrays and Collections 2

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!