List.remove()无法在c#中工作

时间:2018-05-24 14:22:04

标签: c# list

我正在尝试从列表中删除客户,如下所示。

customerList.Remove(customer);

我在运行之前和之后显示整个列表,它显示没有任何更改。我在这里看了另一篇文章:"List.Remove" in C# does not remove item?但是我无法辨别出这个解决方案是如何应用于我的。

我知道我需要直接从列表中获取对象,而不是它的副本。我只是不确定这是同一个案例,如果是的话我会感激一些帮助!

string file = @"C:~\bin\Debug\Customer.xml";
List<Customer> customerList = new List<Customer> { };
XmlSerializer customerSerializer = new XmlSerializer(customerList.GetType());
using (StreamReader customerStreamReader = new StreamReader(file))
{
    customerList = (List<Customer>)customerSerializer.Deserialize(customerStreamReader);
}
Console.WriteLine();
customerList.Remove(customer);

0 个答案:

没有答案