P. 1
C# Sharp Eric Butow Tommy Ryan

C# Sharp Eric Butow Tommy Ryan

|Views: 1,184|Likes:
Published by erorhaner
C# Sharp Eric Butow Tommy Ryan.pdf
C# Sharp Eric Butow Tommy Ryan.pdf

More info:

Published by: erorhaner on Oct 25, 2009
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less

08/15/2013

pdf

text

original

C#

138

ENTER SINGLE-DIMENSIONAL ARRAYS

083601-X Ch07.F 10/18/01 12:00 PM Page 138

Á Type the code that
outputs the opening string
and establishes the array in
the Main method.

‡ Type the code that
outputs the array by iterating
through each element using
the foreach statement.

° Run the program by
pressing the F5 key.

I The prime number array
appears on the screen.

· Save the program as the
filename.

USING ARRAYS 7

You can omit optional parts of the single-dimensional array
argument. One way is to omit the size of the array.

int[] values = new int[] {1, 2, 3, 5, 7, 11};

string[] letters = new string[] {"A", "B", "C"};

Another way is to omit the new statement altogether.

int[] values = {1, 2, 3, 5, 7, 11};

string[] letters = {"A", "B", "C"};

139

083601-X Ch07.F 10/18/01 12:00 PM Page 139

Properties

⁄ Click Start Programs
Microsoft Visual Studio .NET
7.0 Microsoft Visual
Studio .NET 7.0.

I The Start page appears.

¤ Click New Project.

I The New Project window
appears.

‹ Click the Console
Application icon in the
Templates pane.

› Type a name for the file.

ˇ Click OK.

C# lets you declare multidimensional arrays for

processing a large number of values in one
argument. A multidimensional array arranges its data
similar to the way a spreadsheet does.

C# multidimensional arrays let you specify two or three
elements in the array for two-dimensional and three-
dimensional arrays, respectively. You can use two-
dimensional arrays for specifying coordinates such as with
the row and column in a spreadsheet, on a map, or on a
game board such as those for checkers and chess.
Programmers use two-dimensional arrays for such tasks as
image processing.

A three-dimensional array lets you specify three elements.
For example, you can store a name in three dimensions —
first name, middle name, and last name.

Just as with single-dimensional arrays, you can specify the
number of elements in each dimension in the rectangular
brackets after you declare the array type. If you think of the
array as the table, C# lists the number of rows first and the
number of columns second. If you have a three-dimensional
array, then the third dimension appears last in the bracket.

You can also specify initial values for the array in the same
order as you have them in the rectangular brackets. Like
single-dimensional arrays, values appear in curly braces
after you initialize the array with the new operator.

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->