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

Last Updated on May 26, 2022 by Roshan Parihar

In this tutorial, learn how to convert int to string in C#. The short answer is to use the C# ToString() method to change an integer to a string type. The conversion of one type of variable to another type is a type of type casting or type conversion.

You can also convert the integer type to a string type using the concatenation (+) operator in C#. Concatenation is the way of adding the variables that are also useful for conversion to string type. However, some other methods also available in C# for conversion.

So, let’s start converting the int to string with the examples given here.

How to Convert Int to String Using ToString() in C#

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

If the integer variable is ‘myNum’, you have to use the method as myNum.ToString() as given in the example below.

Output

The string value of myNum is: 21

The above showing that the value 21 is first declared as an integer using int with variable myNum. After that, it is converted to string using the myNum.ToString() method. The output results in the value 21 and it is an int to string converted value.

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

If you want to convert int to string, you can use the concatenation of the variable in C#. The concatenation is the way of using the plus (+) operator to add the integer variable with the string. The addition of a variable converts it to the required 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 added with the string variable during the declaration using concatenation. This addition of the integer variable with a string variable converts it 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. You also have to 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.

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.