C# Language String.Format

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Introduction

The Format methods are a set of overloads in the System.String class used to create strings that combine objects into specific string representations. This information can be applied to String.Format, various WriteLine methods as well as other methods in the .NET framework.

Syntax

  • string.Format(string format, params object[] args)
  • string.Format(IFormatProvider provider, string format, params object[] args)
  • $"string {text} blablabla" // Since C#6

Parameters

ParameterDetails
formatA composite format string, which defines the way args should be combined into a string.
argsA sequence of objects to be combined into a string. Since this uses a params argument, you can either use a comma-separated list of arguments or an actual object array.
providerA collection of ways of formatting objects to strings. Typical values include CultureInfo.InvariantCulture and CultureInfo.CurrentCulture.

Remarks

Notes:

  • String.Format() handles null arguments without throwing an exception.
  • There are overloads that replace the args parameter with one, two, or three object parameters.


Got any C# Language Question?