C# 8.0:
using System;
using System.Linq;
...
var Arr = RandomIntArr(-2,2,10);
Console.WriteLine(Arr.Where(x=>x!=0).Aggregate((x,y)=>x*y));
static int[] RandomIntArr(int Min, int Max, int ArrLen) {
Random rnd = new Random();
int[] Out = new int[ArrLen];
for (int i = 0; i < ArrLen; i++) Out[i] = rnd.Next(Min, Max+1);
return Out;
}
C# 8.0:
using System;
using System.Linq;
...
var Arr = RandomIntArr(-2,2,10);
Console.WriteLine(Arr.Where(x=>x!=0).Aggregate((x,y)=>x*y));
...
static int[] RandomIntArr(int Min, int Max, int ArrLen) {
Random rnd = new Random();
int[] Out = new int[ArrLen];
for (int i = 0; i < ArrLen; i++) Out[i] = rnd.Next(Min, Max+1);
return Out;
}