C# String.Format: Format Specifiers, Numbers, Dates, and Padding
string.Format composes a string by replacing numbered placeholders ({0}, {1}, …) with supplied values. If you are looking for a practical answer to "string.format c#", the short version is that it is useful when you want a reusable format template, especially for localization or external configuration.
It has been superseded by string interpolation in most inline scenarios, but it remains a strong choice when the format string is stored externally or when you need to reuse a template.
On this page
- Common C# Format Specifiers
- Basic Syntax
- Numeric Format Specifiers
- Alignment and Column Padding
- Date and Time Formatting
- Custom Numeric Format Strings
- FAQ
- When should I use string.Format instead of interpolation?
- Is string.Format still relevant in modern C#?
- Culture-Aware Formatting
- string.Format vs String Interpolation
Common C# Format Specifiers
| Format | Example | Result |
|---|---|---|
N2 | string.Format("{0:N2}", 1234.5) | 1,234.50 |
F2 | string.Format("{0:F2}", 1234.5) | 1234.50 |
D4 | string.Format("{0:D4}", 42) | 0042 |
P1 | string.Format("{0:P1}", 0.256) | 25.6% |
Use a format specifier after the placeholder, such as {0:N2} for two decimal places or {0:D4} for a four-digit integer padded with zeroes.
Every Console.WriteLine call that accepts a format string uses the same composite formatting rules internally.
Basic Syntax
Numeric Format Specifiers
Alignment and Column Padding
A format item can include an alignment component: {index,width:format}. Positive width right-aligns; negative width left-aligns.
Date and Time Formatting
Custom Numeric Format Strings
Use #, 0, and other picture characters for fully custom layouts.
FAQ
When should I use string.Format instead of interpolation?
Use string.Format when the format template is stored externally or reused across many call sites. Use interpolation for straightforward inline message building.
Is string.Format still relevant in modern C#?
Yes, especially for localization, reusable templates, and scenarios where the format string is not hard-coded inline.
Culture-Aware Formatting
string.Format vs String Interpolation
Both produce the same output. Choose based on your scenario.
| Scenario | Prefer |
|---|---|
| Inline, literal format string | String interpolation $"..." |
| Format string from a resource / config | string.Format |
| Localized UI messages | string.Format with IFormatProvider |
| Logging frameworks (structured logging) | Message templates ({PropertyName}) |
| Building report columns with alignment | string.Format with ,width |
Take It Further

The community's favorite C# guide. Teaches every concept you just read about with clarity.
The C# Player's Guide: 5th Edition · RB Whitaker
Get it on Amazon →As an Amazon Associate I earn from qualifying purchases.
Related Articles
Use the $ prefix in C# to embed expressions in string literals. More readable than string.Format, and it supports format specifiers.
Learn the most commonly used C# string methods, including Contains, StartsWith, Split, Replace, Trim, Substring, IndexOf, Join, and padding examples.
Use StringBuilder in C# for efficient string building in loops. Unlike immutable strings, it reuses the same buffer to avoid repeated memory allocations.
Learn C# DateTime.ToString formats for yyyy-MM-dd, yyyyMMdd, HH:mm:ss, ISO 8601, filenames, logs, and common mistakes such as mm vs MM and hh vs HH.
Convert a string to int in C# with int.Parse, int.TryParse, and Convert.ToInt32. Safely handle null, empty, invalid, and overflow input.