【发布时间】:2023-03-14 00:08:02
【问题描述】:
这是一段代码:
XNamespace z = "#SomeSchema";
var listCols = new HashSet<Col>();
var colNameList = new List<string>(..some values..);
var xElementList = doc.Descendants(z + "row");
return new HashSet<Row>(xElementList .Select(x=> new Row
{
Col= new List<Col>(listCols).Select(col =>
{
col.Value= (string)x.Attribute(colNameList.First(colName=> colName == col.Name));
return col;
}).ToList()
}));
错误在于,返回值包含一个行列表,但所有这些行都具有完全相同的值(对于 Col 值)。
例如,行[1].Col[1].Value == Row[2].Col[2].Value
而且这些值应该完全不同。我正在从 Xml 文件中获取这些值。当我调试 xElementList 时,值是不同的,但是当我尝试使用它们创建行时,所有行都是相同的。 实际上,Rows 有相同的 Columns 列表,这是 xElementList 的最后一条记录。
我做错了吗?
谢谢。
【问题讨论】: