【发布时间】:2015-06-07 16:52:29
【问题描述】:
极点.Count();适用于一维数组,有没有办法,如何用二维数组做到这一点?
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();
}
}
}
或者我如何计算二维数组中的元素 == x?
【问题讨论】: