get each value from each List

i have this code :

 public static void UpdateLmidInGrentyDet(List<long> GPKEY, List<long> LMID)
        {
            
            

            long gid = 0, mid = 0;
            foreach (var item in GPKEY)
            {
                gid = item;

            }
            foreach (var item in LMID)
            {
                mid = item;
            }
            SetIds(gid, mid);
        }
        private static void SetIds(long GID,long MoveID)
        {
             using (EF.LoansDBEntities ef = new EF.LoansDBEntities())
            {
                
                    var query = (from a in ef.GuarantyDet
                                 where a.PayRunId == GID
                                 select a).FirstOrDefault();

                    query.LMID = MoveID;
                    ef.SaveChanges();
                
            }
        }

Open in new window


i need to pull out the first value from the first loop then its need  to wait then go to the second foreach loop pull the value from there then wait then commit the function and return to the first loop pull the second value and run again and again depend the values in the first List
how can i do it ?
or maybe there is a better way to do this ...
Tech_MenAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

anarki_jimbelSenior DeveloperCommented:
First, I'd specify, do these lists have the same length?

Also, what do you mean saying "then wait then commit "? Is some time interval required before or after you do saving?

To get values from list I'd use simple for statement, with a counter, where you may get lists values by index.
This loop can be limited by a lower length if lists have different lengths. After you get these values - save them, inside the loop. Then go to the next iteration.

I can think about more tricky scenarios, "producer./consumer" etc., but not really sure what's required.
Tech_MenAuthor Commented:
hi

they have the same length yes
i need to get the first value from the first list then get the first value from the second list then
run the SetIds function and return again from the start
anarki_jimbelSenior DeveloperCommented:
        public static void UpdateLmidInGrentyDet(List<long> GPKEY, List<long> LMID)
        {

            for (int index=0; index < Math.Min(GPKEY.Count, LMID.Count); index++)
            {
                SetIds(GPKEY[index], LMID[index]);
            }
        }

Open in new window


or

        public static void UpdateLmidInGrentyDet(List<long> GPKEY, List<long> LMID)
        {

            for (int index=0; index < GPKEY.Count; index++)
            {
                SetIds(GPKEY[index], LMID[index]);
            }
        }

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.