It just won’t work, because you get attached to delete the new list (the new keyword dictates this), and not one of the ones you just entered. For example, the following code creates two different lists, since they are not the same list, however they look the same:
var list0 = new List<int> { 1, 2 }; var list1 = new List<int> { 1, 2 };
However, the following creates one single list, but two links to the same list:
var list0 = new List<int> { 1, 2 }; var list1 = list0;
Therefore, you must keep a link to the lists that you put there if you want to act with them in the future in order to:
var list0 = new List<int> { 1, 2 }; listOfLists.Remove(list0);
source share