Deleting a specific item of an array

arrays, c#, indexing

Solution

Array is immutable class, you can't change it, all you can do is to re-create it:

List<String> list = columns.ToList(); // <- to List which is mutable
list.RemoveAt(MY_INT_HERE);           // <- remove 
string[] columns = list.ToArray();    // <- back to array

May be the best solution is to redesign your code: change immutable array into `List<String>`:

  List<String> columns = ...
  columns.RemoveAt(MY_INT_HERE);

Problem

``` string[] columns ``` I want to delete the item on an index specified by a variable of type int. How do I do this ? I tried ``` columns.RemoveAt(MY_INT_HERE); ``` But apparently this does not works.

Original source

Related problems