c# - List.remove() 在 C# 中不起作用
问题描述
我正在尝试从列表中删除客户,如下所示。
customerList.Remove(customer);
我在运行之前和之后显示了整个列表,它表明没有任何改变。我在这里查看了另一篇文章:C# 中的“List.Remove”不删除项目?但我无法辨别这个解决方案是如何应用于我的。
我知道我需要直接从列表中获取对象,而不是它的副本。我只是不确定这是不是同样的情况,如果是这样,我将不胜感激!
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);
解决方案
推荐阅读
- php - 如何修复显示 page/1/ 的分页
- java - 如何使用 JAVA 中的嵌套 for 循环打印以下模式?
- java - 覆盖没有别名的spring bean,它也是父级
- python - 在烧瓶中导入 YAML
- angular - 错误 TS2339:类型“{生产:布尔值”上不存在属性“对话流”;}'
- c++ - 为 c++ 源文件构建 debian 包时出错
- android - RecyclerView 在滚动时丢失了它的项目位置
- javascript - 如何在javascript中分割文本
- unity3d - 需要帮助实施 Perforce depot 或 GitHub repot,允许异地云托管与本地计算机之间的现场主服务器同步
- pandas - 在 pandas 的 groupby 期间根据列是否包含特定字符串来创建变量