Click here to Skip to main content
15,888,803 members
Home / Discussions / C#
   

C#

 
GeneralRe: c# back up program ? :S Pin
Not Active17-Sep-09 12:06
mentorNot Active17-Sep-09 12:06 
GeneralRe: c# back up program ? :S Pin
booo2222222222222217-Sep-09 12:13
booo2222222222222217-Sep-09 12:13 
GeneralRe: c# back up program ? :S Pin
EliottA17-Sep-09 12:16
EliottA17-Sep-09 12:16 
GeneralRe: c# back up program ? :S Pin
booo2222222222222217-Sep-09 12:21
booo2222222222222217-Sep-09 12:21 
GeneralRe: c# back up program ? :S Pin
Richard MacCutchan17-Sep-09 23:03
mveRichard MacCutchan17-Sep-09 23:03 
AnswerRe: c# back up program ? :S Pin
Vimalsoft(Pty) Ltd17-Sep-09 20:45
professionalVimalsoft(Pty) Ltd17-Sep-09 20:45 
Questionforeach simple question Pin
JollyMansArt17-Sep-09 10:14
JollyMansArt17-Sep-09 10:14 
AnswerRe: foreach simple question Pin
Ian Shlasko17-Sep-09 10:28
Ian Shlasko17-Sep-09 10:28 
Foreach doesn't loop through the possible indices, but the elements itself... In your first example, you'd actually want something like:
foreach (int i in MyList)
  Messagebox(i);

Assuming MyList is a list of integers... You're looping through the contents, not the indices.

In your second example, foreach wouldn't really help, as it's designed to operate on one element at a time, with no knowledge of the next one... You want a plain old "for," but the trick is to remember the syntax:
for ([initializer]; [condition]; [step])

The "step" part doesn't necessarily have to be just incrementing... You could do this:
for (int i = 0; i < MyList.Count; i += 2)

...to work with every other element in the list.

Proud to have finally moved to the A-Ark. Which one are you in?
Developer, Author (Guardians of Xen)

QuestionRe: foreach simple question Pin
JollyMansArt17-Sep-09 12:04
JollyMansArt17-Sep-09 12:04 
AnswerRe: foreach simple question Pin
PIEBALDconsult17-Sep-09 12:08
mvePIEBALDconsult17-Sep-09 12:08 
QuestionRe: foreach simple question Pin
JollyMansArt17-Sep-09 12:15
JollyMansArt17-Sep-09 12:15 
QuestionRe: foreach simple question Pin
JollyMansArt17-Sep-09 12:22
JollyMansArt17-Sep-09 12:22 
AnswerRe: foreach simple question Pin
PIEBALDconsult17-Sep-09 13:06
mvePIEBALDconsult17-Sep-09 13:06 
AnswerRe: foreach simple question Pin
Ian Shlasko17-Sep-09 12:21
Ian Shlasko17-Sep-09 12:21 
AnswerRe: foreach simple question Pin
Luc Pattyn17-Sep-09 12:21
sitebuilderLuc Pattyn17-Sep-09 12:21 
AnswerRe: foreach simple question Pin
Christian Graus17-Sep-09 10:28
protectorChristian Graus17-Sep-09 10:28 
AnswerRe: foreach simple question Pin
PIEBALDconsult17-Sep-09 10:32
mvePIEBALDconsult17-Sep-09 10:32 
GeneralRe: foreach simple question Pin
Christian Graus17-Sep-09 12:03
protectorChristian Graus17-Sep-09 12:03 
GeneralRe: foreach simple question Pin
PIEBALDconsult17-Sep-09 12:05
mvePIEBALDconsult17-Sep-09 12:05 
GeneralRe: foreach simple question Pin
Christian Graus17-Sep-09 12:09
protectorChristian Graus17-Sep-09 12:09 
GeneralRe: foreach simple question Pin
Ian Shlasko17-Sep-09 12:30
Ian Shlasko17-Sep-09 12:30 
GeneralRe: foreach simple question Pin
JollyMansArt17-Sep-09 12:36
JollyMansArt17-Sep-09 12:36 
GeneralRe: foreach simple question Pin
PIEBALDconsult17-Sep-09 13:35
mvePIEBALDconsult17-Sep-09 13:35 
GeneralRe: foreach simple question Pin
JollyMansArt17-Sep-09 12:09
JollyMansArt17-Sep-09 12:09 
AnswerRe: foreach simple question Pin
Not Active17-Sep-09 13:26
mentorNot Active17-Sep-09 13:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.