0

I needed to remove the first element from an array in my program. Here is the code:

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

This returns the difference between the original array and an array with the to be removed element. However, it also removes duplicates (I think).

When I input

average 10 20 10 30

it returns

10 20 30

Job done, but I don't want it to remove duplicates. How do I get it to stop removing duplicates?

1
  • 1
    I do realize that this question is a simalar question. Oops! Commented Jun 26, 2015 at 19:53

2 Answers 2

1

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

Instead of using LINQ Except, you could use Skip instead:

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

input = input.Skip(1).ToArray();
Sign up to request clarification or add additional context in comments.

Comments

0

Assuming the input variable has the type of List, you should be able to use:

input.Remove(input[0])

Remove will remove the first matching element it finds in the list.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.