How to Convert Int to String in C# (C-Sharp)

Last Updated on May 1, 2024 by Roshan Parihar

To convert int to string in C#, use the integer variable followed by ToString() method. The conversion of one type of variable to another type is a type of type casting or type conversion.

You can also use the concatenation (+) operator to add the integer to the string to make it a string. Let’s find out the examples given below.

Convert Int to String Using ToString() in C#

If you want to convert the integer type to string type in C#, you can use the integer variable followed by the ToString() function. It does not require any argument to pass with the method for the conversion.

Output

The string value of myNum is: 21

If the integer variable is ‘myNum’, you have to use the method as myNum.ToString() as given in the example. The above example shows that the value 21 is first declared as an integer using int data type. After that, it is converted to a string using the myNum.ToString() method.

Using String Concatenation (+) to Change Int to String in C#

You can use the concatenation (+) operator to add the integer variable to the string. The addition of a variable converts it to the string type as given in the example below.

Output

The string value of myNum is: 21

In the above example, the variable myNum is declared as an integer using the int data type. After that, the string variable myStr is declared using the string data type.

The integer variable myNum is concatenated to the string variable and converts the integer into a string data type.

C# Built-in Method Convert.ToString() for Conversion

In addition to the above methods, you can also use the C# built-in method Convert.ToString() to convert int to string. Just pass the integer variable as the argument of the built-in method. This converts the variable to the required data in C#.

Output

The string value of myNum is: 21

The above example shows that it first declared the integer type variable using the int data type. After that, it converts the integer type to the string type with the above built-in method.

You May Also Like to Read

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.