Home > Net >  Remove an element from an index array c#
Remove an element from an index array c#

Time:10-04

if from an array like this one

string[] arr={"a", "b"};

Can i modify it in this way?

arr={"a"};

CodePudding user response:

You can do it in the following different ways:

1)

var idx = 1;
arr = arr.Where((s, i) => i != idx).ToArray();
arr = arr.Where(s => s != "b").ToArray();
var filter = {"b"};

arr = arr.Except(​filter);

CodePudding user response:

try this

arr = new string[] { arr[0] };
  • Related