[英]C# OutOfMemoryException on array
我对C#还是很陌生,现在我完全陷入了这个功能。 任何帮助,将不胜感激。
我在mess.Add(firstname);
上收到OutOfMemoryException mess.Add(firstname);
我很确定这是由于数组错误引起的,但我似乎无法使其正常工作。
谁可以正确地指导我?
到目前为止,这是我的代码:
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.