C# 错误CS0116:命名空间不能直接包含字段或方法等成员

C# 错误CS0116:命名空间不能直接包含字段或方法等成员,c#,C#,好的,我正在试着制作一个程序来检查一个程序当前是否正在运行。当我宣布无效时,这给了我一个错误。我是C#的新手,如果这是个愚蠢的问题,我很抱歉 using System; using System.Windows; using System.Collections.Generic; using System.Linq; using System.ServiceProcess; using System.Text; using System.Threading.Tasks; using System

好的,我正在试着制作一个程序来检查一个程序当前是否正在运行。当我宣布无效时,这给了我一个错误。我是C#的新手,如果这是个愚蠢的问题,我很抱歉

using System;
using System.Windows;
using System.Collections.Generic;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;
using Microsoft.VisualBasic.ApplicationServices;

namespace IsProgramRunning
{
    private void IsRunning()
    {
        Process[] pname = Process.GetProcessesByName("VLC Player");
        if (pname.Length > 0)
        {
            MessageBox.Show("Process Running");
        }
        else
        {
            MessageBox.Show("Process Not running");
        }
        System.Threading.Thread.Sleep(5 * 1000);
    }
    static void Main()
    {
        ServiceBase[] ServicesToRun;
        ServicesToRun = new ServiceBase[]
        {
        new Service1()
        };
        ServiceBase.Run(ServicesToRun);


    }
}

如果我将这一切都搞错了,在C++中有一个简单的方法,对于

,对于实例成员和方法,你需要一个。您将命名空间与
类混为一谈

namespace MyAwesomeNameSpace
{
   public class ProgramRunningHelper
   {
       // put your class code here

   }
}

命名空间不能直接包含字段或方法等成员

命名空间可以包含其他命名空间、结构和类


不能直接在这样的命名空间内创建函数,函数必须包含在类中