Repeat loop with pair and sequential output

Asked

Viewed 60 times

3

How can I generate this list in sequential pairs:

Array = Itens.text.Split(","[0]);
int qnt = Array .Length;

    for (int i = 0; i < qnt; i++) 
    {
        TextBox.Text = Array[i].text;
        i++;
        TextBox.Text = Array[i].text;               
    }

that way it doesn’t work, plus its removal the i++ That’s the way it goes:

TextBox.text = Array[0];
TextBox.text = Array[0]; 

TextBox.text = Array[1];
TextBox.text = Array[1]; 

TextBox.text = Array[2];
TextBox.text = Array[2]; 

wanted the way out to be:

TextBox.text = Array[0];
TextBox.text = Array[1]; 

TextBox.text = Array[2];
TextBox.text = Array[3]; 

TextBox.text = Array[4];
TextBox.text = Array[5]; 

and etc., to each loop he rotate me like that. if anyone can help me thank you!

  • What would these pairs be? I didn’t understand very well.

  • index in pairs, Ex TxtProduto.text = ArrayProdutos[1] e TxtQnt.text = ArrayProdutos[2]; afterward TxtProduto.text = ArrayProdutos[3] e TxtQnt.text = ArrayProdutos[4]; and so on

  • You have a array that the product name is in the odd index, and the quantity in the even index, and you want to fill text boxes with these values, but to do what exactly?

  • to display the value of the respective index, you will generate a list of text boxes like this: Product Quantity, Product Quantity etc.

  • This does not generate a list of TextBox. This makes their TextBox which already exist to be filled several times. You will create these TextBox Where? On screen? On report? Your solution is Web Forms?

  • see if it’s clearer now =)

Show 1 more comment

1 answer

2


Array = Itens.text.Split(","[0]);
int qnt = Array .Length;

    for (int i = 1; i < qnt; i += 2)
    {
        TextBox.Text = Array[i-1].text;
        TextBox.Text = Array[i].text;               
    }
  • did not give face, of IndexOutOfRangeException: Array index is out of range.

  • try as I have now

  • is i thought about it too but unsuccessfully, it soon error in Array[i-1]

  • same error appears?

  • Try the While I put

  • I did a debug and now this bringing the inverted items of the array and then falls into Exception, the order I tidied up with i = -1 envy of 0

  • 1

    Thank you very much! it worked

Show 3 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.