gpt4 book ai didi

预期的 c# 标识符?

转载 作者:太空狗 更新时间:2023-10-29 18:03:49 29 4
gpt4 key购买 nike

我正在尝试创建一个程序来将所有文件从一个目录复制到另一个目录。但我遇到了一个基本问题。它说当我尝试在第 52 行编译时需要标识符。

public bool RecursiveCopy()
{
string origDir = @"D:\Documents and Settings\Dub\My Documents\HoN Updates\test";
string destDir = @"C:\Games\HoN";
bool status = false;

//get all the info about the original directory
var dirInfo = new DirectoryInfo(origDir);

//retrieve all the _fileNames in the original directory
var files = dirInfo.GetFiles(origDir);

//always use a try...catch to deal
//with any exceptions that may occur
try
{
//loop through all the file names and copy them
foreach (string file in Directory.GetFiles(origDir))
{
var origFile = new FileInfo(file);
var destFile = new FileInfo(file.Replace(origDir, destDir));

//copy the file, use the OverWrite overload to overwrite
//destination file if it exists

System.IO.File.Copy(origFile.FullName, destFile.FullName, true);

//TODO: If you dont want to remove the original
//_fileNames comment this line out
File.Delete(origFile.FullName);
status = true;
}
Console.WriteLine("All files in " + origDir + " copied successfully!");
}
catch (Exception ex)
{
status = false;

//handle any errors that may have occurred
Console.WriteLine(ex.Message);
}
return status;
}

public string origDir = @"D:\Documents and Settings\Dub\My Documents\HoN Updates\test"; // ERROR HERE
public string destDir = @"C:\Games\HoN"; // ERROR HERE

private static void RecursiveCopy(origDir, destDir)
{
Console.WriteLine("done");
Console.ReadLine();
}

最佳答案

您没有在此处为参数列表提供类型标识符

static void RecursiveCopy(origDir, destDir)

应该是

static void RecursiveCopy(string origDir, string destDir)

关于预期的 c# 标识符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1225214/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com