小编Sig*_*gma的帖子

C#:如何检测数组中的重复值并以每个重复值只处理一次的方式处理它们?

我写了这个简单的程序:

    class Program
    {
        static void Main(string[] args)
        {
            Console.Write("Number of elements in the array: ");
            int numberOfElements = int.Parse(Console.ReadLine());
            int[] array = new int[numberOfElements];
            for(int i = 0; i < numberOfElements; i++)
            {
                Console.Write($"Element no {i+1}: ");
                array[i] = int.Parse(Console.ReadLine());
            }
            for(int i = 0; i < array.Length; i++)
            {
                int count = 0;
                for(int j = 0; j < array.Length; j++)
                {
                    if(array[i] == array[j])
                    {
                        count++;
                    }
                }
                Console.WriteLine($"{array[i]} appears " + count + " times");
            } …
Run Code Online (Sandbox Code Playgroud)

c# for-loop

20
推荐指数
3
解决办法
1064
查看次数

标签 统计

c# ×1

for-loop ×1