如何在不删除重复项的情况下从数组中删除元素。在 C#

How to remove an element from an array WITHOUT removing duplicates. in C#

我需要从程序中的数组中删除第一个元素。这是代码:

input = input.Except(new string[] {input[0]}).ToArray();

这returns原始数组和要删除元素的数组的区别。但是,它也会删除重复项(我认为)。

当我输入

average 10 20 10 30

它returns

10 20 30

工作完成,但我不希望它删除重复项。如何让它停止删除重复项?

I needed to remove the first element from an array in my program.

而不是使用 LINQ Except, you could use Skip 而是:

Bypasses a specified number of elements in a sequence and then returns the remaining elements.

input = input.Skip(1).ToArray();

假设输入变量的类型是List,你应该可以使用:

input.Remove(input[0])

删除将删除它在列表中找到的第一个匹配元素。