1

谁能给我正确的语法如何在 vb.net 中编写以下代码

public static void CopyFiles(string fromFolder, string toFolder)
{
    Parallel.ForEach<string>(Directory.EnumerateFiles(fromFolder, "*"), f =>
    {
        File.Copy(f, toFolder + @"\" + Path.GetFileName(f), true);
    });
}

我尝试使用 developerfusion.com/tools/convert/csharp-to-vb 进行转换,转换后的代码是:-

Public Shared Sub CopyFiles(fromFolder As String, toFolder As String)

    Parallel.ForEach(Of String)(Directory.EnumerateFiles(fromFolder, "*"), Function(f) 
    File.Copy(f, toFolder & "\" & Path.GetFileName(f), True)
    End Function)

End Sub

及其抛出编译时异常。请让我知道,这段代码出了什么问题。

4

1 回答 1

2

当您没有返回值时,您正在创建一个函数,请尝试创建一个子例程。看看这是否有效。

Public Shared Sub CopyFiles(fromFolder As String, toFolder As String)
    Parallel.ForEach(Of String)(Directory.EnumerateFiles(fromFolder, "*"),
        Sub(f)
            File.Copy(f, toFolder & "\" & Path.GetFileName(f), True)
        End Sub)
End Sub
于 2013-03-26T03:13:28.057 回答