Resolved Foreach in not iterating through values

Anonymous

Well-known member
Joined
Sep 29, 2020
Messages
94
Programming Experience
Beginner
I am developing an application where I have to perform some update operation on each machine in the database. Every machine has a unique Id. Then there is also an area code under which several machines come. Area codes are also unique. I am reading these ids from the database and storing them in a list and then I want to hit the API one by one using these Ids. The API will give me a response which I have to read and update the database accordingly . I am using foreach but I don't know what mistake I am doing that it is not iterating to the second element(second id) of the list and I am not able to call the function with the 2nd Id to hit the API.

C#:
public static void ProcessIds(string areacode1, string areacode2)
{
    // this is working fine I am getting correct values
    List<IntermediateAPIRequest.IntermediateIds> Ids =
                                              GetIntermediateIDList(areacode1, areacode2);
   
    APIRequest apiRequest = new APIRequest();
    foreach (IntermediateAPIRequest.IntermediateIds id in Ids)
    {

       //code for creating API request--this now fetches the 1st Id from
       // the list and creates the request

        APIresponse result = GetAPIResponsePerID(URL, id.machineID, apiRequest);

        //Code for dealing with the response, for the time being I am
        // simply displaying it onto the console.
     } // end of foreach loop
}

I am able to read the response properly. The main issue is that I am not able to call the api with the 2nd value in the list.

Please let me know if I need to add more code for clarification.
 
You need to debug the code and explain EXACTLY what is happening. Execution doesn't just jump out of a loop for no reason. Assuming your system isn't broken in some way, either you're exiting the loop explicitly, or there are no more items in the list being enumerated or an exception is being thrown.
 

Latest posts

Back
Top Bottom