[C#] foreach loop corrent index
- by Eyla
Is there anyway to know the current run of a foreach without have to:
Int32 i;
foreach
i++;
or is that the best option i got?? Also, how can i know the maximum number of items on that loop?? What i am trying to do is update a progressbar during a foreach loop on my form
Thanks
This is what i got
foreach (FileInfo file in DirectoryFiles)
{
if ((file.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden || (file.Attributes & FileAttributes.System) == FileAttributes.System)
continue;
backgroundWorkerLoadDir.ReportProgress(i, file.Name);
System.Threading.Thread.Sleep(10);
}