
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
String Formatting with ToString in C#
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
using System; public class Program { public static void Main() { int value = 55; string res = value.ToString("000"); Console.WriteLine(res); } }
Output
055
- Related Articles
- String Formatting in C# using %
- String Formatting in C# to add padding
- UInt32.ToString() Method in C# with Examples
- UInt16.ToString Method in C# with Examples
- UInt64.ToString() Method in C# with Examples
- How to compare Python string formatting: % with .format?
- String Formatting in Python using %?
- String Formatting Operator in Python
- String Formatting in Java using %
- String Formatting in C# to add padding on the right
- Int64.ToString() Method in C#
- How does string formatting work in PowerShell?
- C# Enum ToString() Method
- C# Int16.ToString() Method
- Pattern toString() method in Java with examples

Advertisements