The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
 All Forums
 Origin Forum for Programming
 Forum for Origin C
 foreach, C# reference material

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
CStorey Posted - 04/09/2002 : 3:36:49 PM
I couldn't find any information in the Origin documentation about the 'foreach' statement.

Here's a reference to the complete C# (pronounced C 'sharp') specifications. It's a huge word document which is horrible to use as a refenernce, but it's better than nothing.

http://download.microsoft.com/download/VisualStudioNET/Utility/V36/W98NT42KMeXP/EN-US/csharp_36.exe



Craig Storey
Origin WebRing Member - http://g.webring.com/hub?ring=originwebring
2   L A T E S T    R E P L I E S    (Newest First)
gavin.read Posted - 05/23/2002 : 10:20:57 AM
You might consider foreach to be a list operator. Perl and other Unix scripting languages use foreach as;

foreach (member_of_list) {

do something dead useful;

}




easwar Posted - 04/13/2002 : 8:07:08 PM
Hello,

It is probably not necessary to go thru all that documentation from Microsoft to understand what foreach does in Origin C.

The foreach construct allows you to loop thru the collection of all objects in a class.

Consider the following example:

void test1()
{
// Delcare worksheet object
Worksheet wks("Data1");
// Loop thru all columns of the worksheet
foreach(Column col in wks.Columns)
{
printf("Column name: %s\n",col.GetName());
}
}

The Worksheet object contains a collection of Columns, and foreach is used here to loop thru all columns in the data1 worksheet.

Let us look at another example: The Project class consists of a collection of Pages (Worksheets, Matrices, Graphs, Notes etc). A Page in turn is a collection of Layers (Graphs can have multiple layers, Worksheet has only 1 layer etc.). If the Page is a Worksheet, then the Layer then consists of a collection of Columns.

In the code below, foreach is used first to loop thru all Pages of the Project, and then to loop thru all columns of Worksheet Pages.

void test2()
{
// Declare Project to point to current project
Project proj;
// Loop thru all Pages (windows) in Project
foreach(PageBase pb in proj.Pages)
{
// Check Page (window) type. Worksheet is type = 2
int iType = pb.GetPageType();
//if Page is Worksheet, then
if(iType == 2)
{
// Cast the PageBase object to a Page object
Page pg = pb;
// Report name of the Page
printf("Page name: %s\n",pg.GetName());
// Loop thru all layers of the Page (Wks has only one layer)
foreach(Layer ly in pg.Layers)
{
// Cast the Layer object to a Worksheet object
Worksheet wks = ly;
// Loop thru all Colums of the Worksheet
foreach(Column col in wks.Columns)
{
// Report name of Column
printf(" Column name: %s\n",col.GetName());
}
}

}
}
}


You can look for more examples on using foreach by searching for it in the Origin C Help file.

Easwar
OriginLab.

P.S. This forum removes all tabs/indents and so the code examples above do not look good, but they should work fine!

The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000