How can I identify when I am on the last record in a foreach loop? I am using C# in a Method Directive.
Thanks,
Bill Short
Newtown, PA
How can I identify when I am on the last record in a foreach loop? I am using C# in a Method Directive.
Thanks,
Bill Short
Newtown, PA
A foreach loop by nature iterates through every record. If you need to iterate until a certain record in the set, you should use a for loop. You can also use LINQ to identify the last record in the query, then use a foreach loop to stop at the last record.
I’m curious what you need to identify the last record for, if you don’t mind sharing!
Thanks for the reply and sure I don’t mind sharing at all.
The method directive runs when a qualified mfg record is added. The first for each loop gets all of the BOM\Rev’s that the component part is listed on (PartMtl table). Inside of that loop the second for each loop goes through the PartRev table of the parent part from PartMtl to get approved revs. From there I identify the highest approved rev for each parent part and write a new record to UD05. We need to keep a revision history of these changes for certain parts.
I need to know when I am on the last record of the loop so that I know when to write to UD05 so that I only have to do that once.
In E9 I used “If LAST-OF” in ABL.
Thanks,
Bill