数组上的C#OutOfMemoryException

Mat*_*eno 1 c# wcf web-services

我是C#的新手,现在我完全陷入了这个功能.任何帮助,将不胜感激.

我得到一个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;
Run Code Online (Sandbox Code Playgroud)

Chr*_*air 8

你有一个错字.你不小心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
Run Code Online (Sandbox Code Playgroud)