pole.Count(); works for 1D array, is there way, how to do that with 2D array?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication4___TEST
{
class Program
{
static void Main(string[] args)
{
string[] pole = new string[3];
int[,] array = new int[2, 2];
array[1, 1] = 1;
array[1, 2] = 2;
array[2, 1] = 2;
array[2, 2] = 1;
pole[1] = (Console.ReadLine());
pole[2] = (Console.ReadLine());
Console.Write("Zadej p: ");
string p = (Console.ReadLine());
int count = pole.Count(x => x == p)
Console.WriteLine("{0} se vyskytuje v poli {1}-krát", p, count);
Console.ReadLine();
}
}
}
Or how can I count elements == x in 2D array?
Use .OfType():
Print: 2 Link: https://dotnetfiddle.net/c9Uluj
P.S. array indexing starts at 0