Increase in loop For not working

1

I have a for loop that does not work properly for me. If I do a Debug, the increment always resets to 0 so it only reaches 1.

Here is part of the code:

First I loop % for to call the userID

var userDataId = client.GetUser(DataSourceId); 

for (int i = 0; i < userDataId.Length; i++)
{ 
    string[] multiUserIDs = new string[] { userDataId[i].List[0].ToString() };

    WS.TaskEntry[] resultGT3 = client.GetTasks3(multiUserIDs);

    for (int s = 0; s < resultGT3.Length; s++)
    {
      file.WriteLine("{0}, {1}, {2}, {3}",
      resultGT3[s].ProjectID,
      resultGT3[s].UserID,
      resultGT3[s].ProjectTitle,
      resultGT3[s].StartDate);
    }

}

Here the s++ always goes to 0 and only goes to 1.

I've also tried it with while , but it has the same result:

int s = 0;
while (s < resultGT3.Length)
{                                            
  file.WriteLine("{0}, {1}, {2}, {3}",
  resultGT3[s].ProjectID,
  resultGT3[s].UserID,
  resultGT3[s].ProjectTitle,
  resultGT3[s].StartDate);
  ++s;
}

Could you help me identify what I'm doing wrong?

    
asked by A arancibia 01.03.2016 в 18:03
source

3 answers

1
  

the increment always resets to 0 so it only reaches 1.

Surely the value of resultGT3.Length is 1 and that is the reason why you do not see change:

for (int s = 0; s < resultGT3.Length; s++)
{
  file.WriteLine("{0}, {1}, {2}, {3}",
  resultGT3[s].ProjectID,
  resultGT3[s].UserID,
  resultGT3[s].ProjectTitle,
  resultGT3[s].StartDate);
}
    
answered by 01.03.2016 в 18:14
0

> > > Of what way could you obtain all the usersID from UserDataId?

Keeping in mind that the service GetTasks3() can receive a list of IDs, you could send an array with several if you previously accumulate them in a list before invoking the method.

var userDataId = client.GetUser(DataSourceId); 

List<string> multiUserIDs = new List<string>();

foreach (var userdata in userDataId)
{ 
    multiUserIDs.Add(userdata.List[0].ToString());
}

WS.TaskEntry[] resultGT3 = client.GetTasks3(multiUserIDs.ToArray());

foreach (var result in resultGT3)
{
  file.WriteLine("{0}, {1}, {2}, {3}",
      result.ProjectID,
      result.UserID,
      result.ProjectTitle,
      result.StartDate);
}

You will notice that now the for are not nested

    
answered by 01.03.2016 в 20:47
0

I found the problem and I was able to solve it.

On the first line of my code:

var userDataId = client.GetUser(DataSourceId); 

Instead of putting the result in the variable var userDataId change it to:

UserData[] userDataId = client.GetUserData(DataSourceId);

This way I could put all the UsersIDs and I could already get what I was looking for.

    
answered by 03.03.2016 в 16:08