Deleting Last Item from Array of String Deleting Last Item from Array of String arrays arrays

Deleting Last Item from Array of String


To remove just the last element use this:

newDeck = newDeck.Take(newDeck.Count() - 1).ToArray();

Your solution removes all Elements that are equal to the last element. For a string, this means, it removes all elements equal to A


You can use Array class to resize:

Array.Resize(ref result, result.Length - 1);


@Flat Eric explained why your solution is not working.

Here is alternate for removing last element:

newDeck = newDeck.Reverse().Skip(1).Reverse().ToArray();

Clarification:

[a, b, c] => Reverse => [c, b, a] => Skip(1) => [b, a] => Reverse() => [a, b]