I have the following code I am trying to “fix”
foreach (System.IO.DirectoryInfo dir in source.GetDirectories())
CopyFilesRecursively(dir, target.CreateSubdirectory(dir.Name),safeFileNames);
foreach (System.IO.FileInfo file in source.GetFiles())
if (safeFileNames)
{
}
The code goes on to do more, but I noticed that the foreach loops don’t contain any {} brackets…
Which of the following will fix this :
foreach (System.IO.DirectoryInfo dir in source.GetDirectories())
{
CopyFilesRecursively(dir, target.CreateSubdirectory(dir.Name),safeFileNames);
}
foreach (System.IO.FileInfo file in source.GetFiles())
{
if (safeFileNames)
{
}
}
or……….
foreach (System.IO.DirectoryInfo dir in source.GetDirectories())
{
CopyFilesRecursively(dir, target.CreateSubdirectory(dir.Name),safeFileNames);
foreach (System.IO.FileInfo file in source.GetFiles())
if (safeFileNames)
{
}
}
Once I’ve fixed the outerloop I can then look at cleaning up the inner loop.
On a side note, nothing more annoying to me than seeing code logic not containing explicit markings of the bounds of the control. You see a lot of this in JS code samples on the web.
Thanks.
First option is right:
If your block statement doesn’t contains any
{}, just next line will be included.