我目前正在使用锯齿状数组:private double[][] array;
并且我像这样加载数组。
加载锯齿状数组
XDocument doc = XDocument.Load("file.Xml");
array = doc.Root.Elements("Month").Select(month => month.Elements().Select(x => (double)x).ToArray()).ToArray();
所以现在我的问题是我需要获取内部数组的长度,正如我所读到的,这是不可能的,所以我需要将 xml 加载到矩形数组中 private double[,] array;
但对于 linq 我不知道如何。
XML 外观
<document>
<Month>
<Depth>-0.25</Depth>
<October>0.95</October>
<November>-0.90</November>
...
</Month>
<Month>
<Depth>-0.5</Depth>
<October>0.47</October>
<November>-0.17</November>
...
</Month>
...
</document>
最佳答案
double[][] array =
doc.Root.Elements("Month")
.Select(month => month.Elements().Select(x => (double)x).ToArray())
.ToArray();
foreach(var innerArray in array)
Console.WriteLine(innerArray.Length); // you can get length of inner array
关于c# - 使用 linq 将 xml 文件加载到二维矩形数组中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21554284/