Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在主方法c#中调用我的方法?_C# - Fatal编程技术网

如何在主方法c#中调用我的方法?

如何在主方法c#中调用我的方法?,c#,C#,我目前正在学习C。我想尝试以下函数,但不知道需要在main方法中添加什么才能使其成功运行: namespace ConsoleApp1 { using System; using System.Linq; public class Program { public int[] SwitchLights(int[] a) { var count = a.Count(t => t == 1);

我目前正在学习C。我想尝试以下函数,但不知道需要在main方法中添加什么才能使其成功运行:

namespace ConsoleApp1
{
    using System;
    using System.Linq;
    public class Program
    {
        public int[] SwitchLights(int[] a)
        {
            var count = a.Count(t => t == 1);
            for (int i = 0; i < a.Length; i++)
            {
                var current = count;
                if (a[i] == 1) count--;
                if (current % 2 == 1) a[i] = a[i] == 1 ? 0 : 1;
            }
            return a;
        }
 static void Main(string[] args)
    {

    }
}
}
名称空间控制台EAPP1
{
使用制度;
使用System.Linq;
公共课程
{
公共int[]开关灯(int[]a)
{
var count=a.count(t=>t==1);
for(int i=0;i

任何帮助都将不胜感激。

您必须或者

1、使方法静态

    public static int[] SwitchLights(int[] a)
    
    static void Main(string[] args)
    {
         SwitchLights(new [] { 1 });
    }
或2,创建程序类的实例

    static void Main(string[] args)
    {
         var program = new Program();
         program.SwitchLights(new [] { 1 });
    }

开关灯需要是静态的。您需要阅读有关OOP概念的文档和适当的教程集……数据结构不要懒惰;)