A simple question about foreach using result from linq

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Tony Johansson

    A simple question about foreach using result from linq

    Hello!

    I have the code below. In the previous code not shown below I have used linq
    to extract some row and
    these have been placed in the var variable result. In my code there is just
    one entry in result but it can be more.
    All works fine the first time I enter the following foreach loop
    foreach(var o in result)
    {
    o.ID = nextParamID.ToS tring();
    o.WorksheetRowI D = item.WorksheetR owID;
    ccrFormObj.myWo rksheetRowParam eterList.Add(o) ;
    nextParamID++;
    }

    but when I enter this same foreach loop the second time
    the collection result is empy. How is that possible I haven't removed any
    entry
    in that collection.

    My logic in the progam is to use this collection set result when I
    enter this foreach loop
    foreach(var o in result)
    {
    o.ID = nextParamID.ToS tring();
    o.WorksheetRowI D = item.WorksheetR owID;
    ccrFormObj.myWo rksheetRowParam eterList.Add(o) ;
    nextParamID++;
    }

    //Code start here
    /////////////////////////
    for (int i = 0; i < myParamRowCount ; i++)
    {
    WorksheetRowPar ameter item = ccrFormObj.myWo rksheetRowParam eterList[i];
    //If we have a change in the actual worksheetRowID we might have to do
    something
    if (item.Worksheet RowID != previousWorkshe etRowID)
    {
    //Check if we have reached a parameter row that is the next
    parameter initiator
    //If true we have not reached this row so add parameter initiatorer
    if (Convert.ToInt3 2(item.Workshee tRowID) <
    workSheetIDList Array[index+1])
    {
    //We must add parameterinitia tor rows because this procedure
    require
    //that parameter initiators must be repeated
    //result is a worksheetRowPar ameter and contain all the
    parameter initiatorer
    //for the first row
    foreach(var o in result)
    {
    o.ID = nextParamID.ToS tring();
    o.WorksheetRowI D = item.WorksheetR owID;
    ccrFormObj.myWo rksheetRowParam eterList.Add(o) ;
    nextParamID++;
    }
    }
    }
    previousWorkshe etRowID = item.WorksheetR owID;
    }


    Can you give me some advice what I should do to keep this result as it is
    without being cleaned.

    //Tony

Working...