Пытаюсь обойти Dictionary с использованием foreach...
// System.Collections.Generic.KeyValuePair[int, XmlIOsystem.OutputClass.NodeStruct]
// Ошибка unbound type name N
foreach(N in inputData.NodeList)
{
}
// Ошибка pattern matches 2 values, while the type 'System.Collections.Generic.KeyValuePair' has 0 fields
foreach((key, value) in inputData.NodeList)
{
}
комментарии в коде показывают, какие ошибки появляются
Вот сокращённое объявление Dictionary на C#
// ...
namespace XmlIOsystem
{
public class OutputClass
{
// ...
public struct NodeStruct
{
// ....
}
// ....
public Dictionary<int, NodeStruct> NodeList = new Dictionary<int, NodeStruct>();
// ....
public void SetDictionaries(InputDataForm IDF, DataGridView NodesDGV, DataGridView BarsDGV,
DataGridView CrossAreasDGV, DataGridView MaterialsDGV, DataGridView LoadsDGV)
{
SetFuncsDictionary (IDF);
SetNodesDictionary (NodesDGV);
SetBarsDictionary (BarsDGV);
SetCrossAreasDictionary(CrossAreasDGV);
SetMaterialsDictionary (MaterialsDGV);
SetLoadsDictionary (LoadsDGV);
}
protected NodeStruct GetNodeStruct(int i, DataGridViewRow Row)
{
NodeStruct S = new NodeStruct( (double) Row.Cells[01].Value, (double) Row.Cells[02].Value, (double) Row.Cells[03].Value,
(Vector3d) Row.Cells[04].Value, (Vector3d) Row.Cells[05].Value, (Vector3d) Row.Cells[08].Value,
(Vector3d) Row.Cells[09].Value, (Vector3d) Row.Cells[06].Value, (Vector3d) Row.Cells[07].Value,
(bool) Row.Cells[10].Value, (bool) Row.Cells[11].Value);
return S;
}
protected void SetNodesDictionary(DataGridView NodesDGV)
{
for (int i = 0; i < NodesDGV.RowCount; i++)
{
NodeList.Add( (Int32) NodesDGV.Rows[i].Cells[0].Value, GetNodeStruct(i, NodesDGV.Rows[i]) );
}
}
// ....
}
}