C#标识符预期? [英] c# identifier expected?

查看:162
本文介绍了C#标识符预期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图创建一个程序将所有文件从一个目录复制到另一个。但我在一个基本问题上运行。它说,当我尝试编译线52 indentifier有望

 使用系统; 
使用System.Collections.Generic;
使用System.Linq的;
使用System.Text;
:使用System.IO;

命名ConsoleApplication1
{
类节目
{
静态无效的主要()
{
}

酒店的公共布尔RecursiveCopy()
{
串origDir = @D:\Documents和Settings\Dub\My Documents\HoN Updates\test
串DESTDIR = @C:\Games\HoN
BOOL状态= FALSE;
//获得所有关于原目录
DirectoryInfo的dirInfo =新DirectoryInfo的(origDir)的信息;
//取回原来的目录
的FileInfo [] =文件dirInfo.GetFiles(origDir)所有_fileNames;
//始终使用的try ... catch来处理
//可能发生

{
//遍历所有文件名的任何异常并复制
的foreach(字符串文件在Directory.GetFiles(origDir))
{
FileInfo的origFile =新的FileInfo(文件);
FileInfo的destFile =新的FileInfo(file.Replace(origDir,DESTDIR));
//复制文件,使用了覆盖超载覆盖
//目标文件(如果存在)
System.IO.File.Copy(origFile.FullName,destFile.FullName,真正的);
// TODO:如果你不想删除原来的
// _名注释此行出
File.Delete(origFile.FullName);
状态= TRUE;
}
Console.WriteLine(+ origDir +中的所有文件,复制成功!);
}
赶上(异常前)
{
状态= FALSE;
//处理可能出现
Console.WriteLine任何错误(ex.Message);
}
返回状态;
}

公共字符串origDir = @D:\Documents和Settings\Dub\My Documents\HoN Updates\test // ERROR HERE
公共字符串DESTDIR = @C:\Games\HoN // ERROR HERE

静态无效RecursiveCopy(origDir,DESTDIR)
{
Console.WriteLine(完成);
到Console.ReadLine();
}
}
}


解决方案

您没有给类型标识符在这里您参数列表

 静态无效RecursiveCopy(origDir,DESTDIR)

 静态无效RecursiveCopy(字符串origDir,串DESTDIR)


I am trying to create a program to copy all the files from one directory to another. But I am running in a basic issue. It says indentifier expected when I try to compile on line 52.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main()
        {
        }

        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
            DirectoryInfo dirInfo = new DirectoryInfo(origDir);
            //retrieve all the _fileNames in the original directory
            FileInfo[] 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))
                {
                    FileInfo origFile = new FileInfo(file);
                    FileInfo 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

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

解决方案

You did not give type identifiers to your argument list here

static void RecursiveCopy(origDir, destDir)

should be

static void RecursiveCopy(string origDir, string destDir)

这篇关于C#标识符预期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆