You can use Remove() method if you already have a reference to the string array that you want to remove like the following:
List<string[]> theList = new List<string[]>();
string[] myStringarray = new string[] { "a", "b", "c" };
theList.Add(myStringarray);
//remove myStringarray from the main list
theList.Remove(myStringarray);
However if you are getting the items from the user and you want to search for an array that contains these elements and remove them, I recommend creating an extension method like the following:
public static class ExtensionMethods
{
public static string[] FindAndRemove(this ICollection<string[]> list, string[] items)
{
string[] removedList = null;
foreach (var stringArray in list)
{
if (stringArray.SequenceEqual(items))
{
removedList = stringArray;
break;
}
}
if (removedList != null)
{
list.Remove(removedList);
}
return removedList;
}
}
Which is mainly search for the first array that its elements equal the passed element in item array (the parameter) and remove it, you can further improve this method and make it remove all the lists that satisfy the condition as following:
public static class ExtensionMethods
{
public static int FindAndRemove(this List<string[]> list, string[] items)
{
return list.RemoveAll(arr => arr.SequenceEqual(items));
}
}
Here I have used RemoveAll from Linq library, which remove all the lists that meet the given condition.
Note that SequecnceEqual also exists inside linq library and used to:
Determines whether two sequences are equal by comparing the elements by using the default equality comparer for their type.