试图将一些 VB 转换为 C#...(也学习 C#)。我有一些代码循环遍历目录中的文件并检索它们的文件信息。我最初在 VB 中有这个,但我正在尝试学习 C#,并且在线转换器不给我将通过 .net 2.0 的代码。
这是错误:
Type and identifier are both required in a foreach statement
这是我的代码:
DirectoryInfo dirInfo = new DirectoryInfo(currentDir);
FileInfo[] files = null;
files = dirInfo.GetFiles();
FileInfo f = default(FileInfo);
foreach (f in files) { ...
}
我试过把,foreach(FileInfo f...
但它给了我一个不同的错误:
A local variable named 'f' cannot be declared in this scope because it would give a different meaning to 'f', which is already used in a 'parent or current' scope to denote something else
我如何解决它?