What is the best way, in terms of performance, to remove a list (a group of elements such as integers or strings) from another list, other than using for or foreach loops?
For example, is there a function that takes a list as a parameter and removes every element in it?, similar to List.AddRange(), which takes a list as a parameter and adds every element from it.
public class ListsManager : MonoBehaviour
{
[SerializeField] private List<int> _list = new List<int>() { 1, 2, 3, 4, 5, 7, 8, 9, 10 };
[SerializeField] private List<int> _listToRemove = new List<int>() { 1, 3, 5, 7, 9 };
void Start()
{
for (int i = 0; i < _listToRemove.Count; i++)
{
_list.Remove(_listToRemove[i]);
}
}
}