Array problem with data coming from a TextBox

0

The inconvenience occurs when I try to display the content of my array in a Label .

The data I try to display of array comes from a TextBox , and they are numeric, since basically what I did was try that when the user enters numbers in a TextBox (separated each one by commas) , create a array , and with Split , isolate those numbers and save them in said array , then go through each space, and save each value in a variable and finally display in a Label said values.

Apparently it's fine, but when running I have the following error:

  

System.FormatException: 'Input string was not in a correct format.'

I do not know what could be wrong, so if someone can help me, it would be very useful for me.

This is my code:

int[] A = txtVA.Text.Split(',').Select(Int32.Parse).ToArray();
int[] B = txtVB.Text.Split(',').Select(Int32.Parse).ToArray();
string cadena=" ";

for (int i = 0; i < 2; i++)
{
    cadena = Convert.ToString(A[i]);
    cadena += cadena;

}
lblre.Text = cadena;
    
asked by Axwell Duarte 28.12.2018 в 18:41
source

1 answer

1

Complete code:

if (string.IsNullOrWhiteSpace(txtVA.Text))
    return;

string cadena = string.Empty;
try
{
    int[] A = txtVA.Text.Split(',').Select(int.Parse).ToArray();
    cadena = string.Join(" ", A);
}
catch { }

lblre.Text = cadena;
lblre.Refresh();

Try this version.

    
answered by 28.12.2018 в 18:58