错误CS1518:预期的类,委托,枚举,接口或结构

时间:2014-06-30 12:17:10

标签: c#

在我的c#程序中,我有第一行:

using System;
using System.Diagnostics;
using System.ComponentModel;


private const string TargetUrl = "http://www.TEST.com";
private const string TorAppLocation = @"C:\Program Files (x86)\test\Lis\lis.exe";
private static readonly string[] InstalledBrowsers
    = new[]{"IExplore","Chrome","Firefox","Safari"};

static private Process _prc;

static private int _reqCounter = 0;
...

编译时返回错误CS1518:预期的类,委托,枚举,接口或结构。

我该如何解决?

2 个答案:

答案 0 :(得分:3)

您只是忘了在类中定义const和其他字段。

编辑:

class Whatever { 

    private const string TargetUrl = "http://www.TEST.com";
    private const string TorAppLocation = @"C:\Program Files (x86)\test\Lis\lis.exe";
    private static readonly string[] InstalledBrowsers = new[]{"IExplore","Chrome","Firefox","Safari"};

    static private Process _prc;

    static private int _reqCounter = 0;

}

答案 1 :(得分:3)

请在班级中定义你的const和成员字段

class Program
    {

        private const string TargetUrl = "http://www.TEST.com";
        private const string TorAppLocation = @"C:\Program File (x86)\test\Lis\lis.exe";
        private static readonly string[] InstalledBrowsers
        = new[]{"IExplore","Chrome","Firefox","Safari"};

        static private Process _prc;

        static private int _reqCounter = 0;
        static void Main(string[] args)
        {
           //code here
        } 
     }