String Formatting with ToString in C#

CsharpProgrammingServer Side Programming

To format a string, first set the value −

int value = 55;

Now to format the integer, use ToString and let’s say we need to set it for three places −

value.ToString("000");

The following is the complete code −

Example

 Live Demo

using System;
public class Program {
   public static void Main() {
      int value = 55;
      string res = value.ToString("000");
      Console.WriteLine(res);
   }
}

Output

055
raja
Published on 31-Aug-2018 13:18:11
Advertisements