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

本文关键字:委托 枚举 结构 接口 CS1518 期望 错误 | 更新日期: 2023-09-27 18:10:44

在我的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:期望类,委托,枚举,接口,或结构。

我怎么解决它?

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

请在类中定义const和member字段

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
        } 
     }

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

EDIT:

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;
}