Convert number to string with ToString method - CSharp Language Basics

CSharp examples for Language Basics:Data Type Format

Description

Convert number to string with ToString method

Demo Code

using System;//from  w  ww.  j  a  va  2 s .  c o m
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Program
{
   static void Main(string[] args)
   {
      // Some number
      int number = 1234;
      // Conversion to text
      //string numberAsText = number; // DOES NOT WORK!
      string numberAsText = number.ToString();
      // Output
      Console.WriteLine("Output of number: " + number);
      Console.WriteLine("Output of text: " + numberAsText);
   }
}

Result


Related Tutorials