数组上出现C#OutOfMemoryException
本文关键字:C#OutOfMemoryException 数组 | 更新日期: 2023-09-27 18:19:45
我对C#还很陌生,现在我完全陷入了这个函数中。如有任何帮助,我们将不胜感激。
我在mess.Add(firstname);
上收到OutOfMemoryException我很确定这是因为阵列故障,但我似乎无法使其工作。
谁能指引我走正确的路?
这是我迄今为止的代码:
public List<string> SelectEmployee(string pkrelation)
{
SDKRecordset inboundSet = IQSDK.CreateRecordset("R_CONTACT", "", "FK_RELATION = " + pkrelation, "");
inboundSet.MoveFirst();
string person = inboundSet.Fields["FK_PERSON"].Value.ToString();
messages.Add(person);
inboundSet.MoveNext();
SDKRecordset inboundSet2 = IQSDK.CreateRecordset("R_PERSON", "", "PK_R_PERSON = " + person, "");
if (inboundSet2 != null && inboundSet2.RecordCount > 0)
{
inboundSet2.MoveFirst();
do
{
string firstname = inboundSet2.Fields["FIRSTNAME"].Value.ToString();
mess.Add(firstname);
inboundSet.MoveNext();
}
while (!inboundSet2.EOF);
return mess;
}
messages.Add("Error, didn't work.");
return messages;// null;
您有一个打字错误。你意外地得到了inboundSet.MoveNext()
,所以很自然地,你的inboundSet2.EOF
永远不会被设置为false
,因为你从来没有真正迭代过它。这会导致一个无限循环最终到达OutOfMemoryException
。
do
{
string firstname = inboundSet2.Fields["FIRSTNAME"].Value.ToString();
mess.Add(firstname);
inboundSet.MoveNext(); // This needs to be inboundSet2!
}
while(!inboundSet2.EOF) //EOF never becomes true causing an infinite loop