如何在主方法c#中调用我的方法?
我目前正在学习C。我想尝试以下函数,但不知道需要在main方法中添加什么才能使其成功运行:如何在主方法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);
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概念的文档和适当的教程集……数据结构不要懒惰;)