Basics

You can use a for statement instead of a foreach statement. Note how much extra programming you must do to make this work.

Example:

static void Main() {

Console.WriteLine("Out of {0} numbers, found {1} Numbers that were greater than five.", iNumberList.GetLength(0), iCount) ;

EnumerateCollection.cs - Notepad

| File Edit Formal Help

using System;

class EnumerateCoiiection {

static void MainQ {

foreach (int ¡Member in iNumberList) {

Consoie.WriteLineC'Out of {0} numbers, found {1} Numbers that were greater than five.", iNumberList,GetLength(O), ¡Count)

, Save as the class name.

Note: See page 35 for more information on saving a file.

Consoie.WriteLineC'Out of {0} numbers, found {1} Numbers that were greater than five.", iNumberList,GetLength(O), ¡Count)

EI] C:\WINNT\Sjistem32\cmd.

Microsoft Windows 2000 [Uersion 5.00.21951 <C> Copyright 1985 2000 Microsoft Corp.

C:\Documents and Settings\Administrator>cd C:\CSharp

C:SCsharp>csc EnumerateCollection.i Microsoft CR) Uisual CS Compiler Ui 6151

Copyright <C> Microsoft Corp

EI] C:\WINNT\Sjistem32\cmd.

Microsoft Windows 2000 [Uersion 5.00.21951 <C> Copyright 1985 2000 Microsoft Corp.

C:\Documents and Settings\Administrator>cd C:\CSharp

C:SCsharp>csc EnumerateCollection.i Microsoft CR) Uisual CS Compiler Ui 6151

Copyright <C> Microsoft Corp

greater than fi<

■ The program displays the message about the results.

Was this article helpful?

0 0

Post a comment