我在我的代码中创建了一个代表医疗患者图表的对象。每个图表对应一位患者。在每个图表中,患者可以进行多次访问或“遭遇”。在每次会面中,患者可以有几个支持文件。
我在遍历第一个索引 [0] 是另一个数组的数组时遇到问题。在下面的代码中,编译器抱怨 (int j = 0; j < chart.DocumentIDs[i].Length; j++) 无效,因为类型对象没有长度属性。但是,DocumentIDs[i] 处的索引是 Int32[]。
我正在尝试生成一个字符串输出,它将列出患者图表的所有内容,首先按遭遇分解,然后按文档 ID 分解。下面是我的代码。如果有人能指出我哪里出错了。我会很感激的。谢谢。
public partial class MainWindow : Window
{
string ChartOutput = "";
public MainWindow()
{
InitializeComponent();
//initialize new chart object
var charts = new[]
{
new
{
MRN= 745654,
Encounters = new int?[]
{
10,11,12
},
DocumentIDs = new object []
{
new int[]
{
110, 1101
}, null, 112
},
DocumentTypes = new object[]
{
new string[]
{
"Consents", "H&P"
}, null, "Intake Questionnaire"
},
DocumentNames = new object[]
{
new string[]
{
"Eartube Surgery",
"Well-Visit Physical"
}, null, "Health Survey"
}
}
};
foreach (var chart in charts)
{
ChartOutput += " Patient MRN#: " +
chart.MRN.ToString() +
" Has the following visits:
" + Environment.NewLine +
Environment.NewLine ;
for(int i =0; I < chart.Encounters.Length; i++)
{
ChartOutput += "Visit Number: " +
chart.Encounters[i].ToString() +
Environment.NewLine;
if (chart.DocumentIDs[i] != null)
{
for (int j = 0; j < chart.DocumentIDs[j].Length; j++)
{
ChartOutput += " Document ID:" +
chart.DocumentIDs[j].ToString() +
Environment.NewLine +
" Document Type: " +
chart.DocumentTypes[j].ToString() +
Environment.NewLine + " Document Name: " +
chart.DocumentNames[j].ToString() +
Environment.NewLine + Environment.NewLine;
}
}
else
{
ChartOutput += " Has No Documents" +
Environment.NewLine +
Environment.NewLine;
}
}
}
}
}
//ChartObject Class
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CodeTester
{
public class ChartObject
{
public ChartObject()
{
RecordClass = "Medical";
}
public string RecordClass {get; private set; }
public int MRN { get; set; }
public object [] Encounters { get; set; }
public object [] DocumentIDs { get; set; }
public object [] DocumentTypes { get; set; }
public object [] DocumentNames { get; set; }
}
}
}