R
Robert Sentgerath
Foreach is a relative handy construct to avoid having to create the classic
"for(int loop = 0; loop < collection.Length; loop++) construct. Though when
I use foreach instead I do not have access to a loop variable that allows me
to display a status message such as "Processing 4 out of 10".
Is there a more elegant way to code the following and avoid having to
declare the index variable?
DirectoryInfo diImport = new DirectoryInfo(processLogPath);
FileInfo[] fiImport = diImport.GetFiles(processLogMask);
int index = 0;
foreach(FileInfo file in fiImport)
{
index++;
DoSomething(file);
statusBar1.Text = String.Format("Processing {0} of {1}", index,
fiImport.Length);
}
Since the methods provided with the IEnumerator interface do not give back
an index, I have somehow the feeling there is no way to avoid declaring the
index type variable.
Any advise appreciated.
"for(int loop = 0; loop < collection.Length; loop++) construct. Though when
I use foreach instead I do not have access to a loop variable that allows me
to display a status message such as "Processing 4 out of 10".
Is there a more elegant way to code the following and avoid having to
declare the index variable?
DirectoryInfo diImport = new DirectoryInfo(processLogPath);
FileInfo[] fiImport = diImport.GetFiles(processLogMask);
int index = 0;
foreach(FileInfo file in fiImport)
{
index++;
DoSomething(file);
statusBar1.Text = String.Format("Processing {0} of {1}", index,
fiImport.Length);
}
Since the methods provided with the IEnumerator interface do not give back
an index, I have somehow the feeling there is no way to avoid declaring the
index type variable.
Any advise appreciated.