Different ways for Integer to String Conversions in C#



The easiest way to convert an integer to a string in C# is using the ToString() method.

Let us see an example −

int a = 100; string str = a.ToString();

Another way is to use Convert.ToString();

b = 50; string str2 = Convert.ToString(b); Console.WriteLine(str2);

The following is the example showing the different ways to convert integer to string.

Example

 Live Demo

using System; class Program {    static void Main() {       int a, b, c;       a = 10;       string str = a.ToString();       Console.WriteLine(str);       b = 50;       string str2 = Convert.ToString(b);       Console.WriteLine(str2);       c = 100;       string str3 = string.Format("{0}", c);       Console.WriteLine(str3);    } }

Output

10 50 100
Updated on: 2020-06-22T07:39:03+05:30

16K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements