How do I convert an int to a string? [duplicate]

0

I want to convert a value of type int to a string to show it in a textbox as it would be the correct way to do it.

    
asked by Edwin Casco 26.09.2017 в 03:22
source

5 answers

1

I hope it serves you:

string miString = miEntero.ToString();
    
answered by 26.09.2017 в 03:27
1
int number;

bool result=Int32.TryParse("160519",number);

Returns true if it converts it well, but false. The converted value to integer saves it in the second parameter (number in this case)

    
answered by 26.09.2017 в 09:58
0

From int to string

MiString = Convert.ToString(5);

From string to int

MiInt = Convert.ToInt32("5"); 
    
answered by 26.09.2017 в 04:01
0

You can do it in the following way:

//Tienes el número en tu variable de tipo int.

int valorNumerico = 5;

//Agregar a la variable texto el valor numérico y le agregas una cadena vacía "".

string texto = valorNumerico + "";
    
answered by 26.09.2017 в 03:33
0

It uses the statico int.TryParse method where it accepts 2 parameters: the first is the string and the second is the variable that will contain the converted value:

int numero;
if(Int32.TryParse("160519", out numero)){
   Console.WriteLine("El valor convertido es {0}", numero);
}
else{
  Console.WriteLine("El valor no es un numero");
}

In case you're wondering, out allows you to send the variable number by reference, not by value which makes it possible to be modified within the method and the value reflected when the execution of the same ends.

    
answered by 26.09.2017 в 14:34