Quote:
Thank you, I thought of that, but I was actually wondering what to code to put there to call it.
As Richard has said, the static
Main
method is called automatically for you - that's why an assembly can only ever have one static method called Main, regardless of how many classes it contains.
Once you have that, you can call your method(s) as necessary:
using System;
using System.Linq;
namespace ConsoleApp1
{
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)
{
int[] myArray = new int[] {1, 2, 3, 4, 5, 6, 7, 8, 9};
Program myProg = new Program();
myArray = myProg.SwitchLights(myArray);
}
}
}