VOOZH about

URL: https://www.geeksforgeeks.org/c-sharp/string-format-method-in-c-sharp-with-examples-set-1/

⇱ String.Format() Method in C# with Examples | Set - 1 - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

String.Format() Method in C# with Examples | Set - 1

Last Updated : 15 Jul, 2025

In C#, Format() is a method of the String Class. This method is used to replace one or more format items in the specified string with the string representation of a specified object. In other words, this method is used to insert the value of the variable or an object or expression into another string.

Example: Demonstration of Format() method of string class.


Output
Hello, Geeks!


This method can be overloaded by passing different types of arguments to it. There are a total of 8 methods in the overload list of the Format() method of which 3 are discussed in this article and the remaining are discussed in Set-2 and Set-3.

  • String.Format(String first, Object second) Method
  • String.Format(String, params Object[]) Method
  • String.Format(IFormatProvider, String, Object) Method
  • String.Format(IFormatProvider, String, Object, Object) Method
  • String.Format(IFormatProvider, String, Object, Object, Object) Method
  • String.Format(IFormatProvider, String, Object[]) Method
  • String.Format(String, Object, Object) Method
  • String.Format(String, Object, Object, Object) Method

1. String.Format(String first, Object second) Method

This method is used to replaces one or more format items in a string with the string representation of a specified object.

Syntax:

public static string Format (string format, object arg0);

Parameter:

  • format: This parameter is the required composite format string.
  • arg0: This parameter is the object to format.

Return Value: This method returns the string. It is a copy of format in which any format items are replaced by the string representation of arg0.

Example:


Output
Tuesday, 11 March 2025


2. String.Format(String, params Object[]) Method 

This method is used to replaces the format item in a specified string with the string representation of a corresponding object in a specified array.

Syntax:

public static string Format (string format, params object[] args);

Parameter:

  • format: This parameter is the required composite format string.
  • args: This parameter is the object array that contains zero or more objects to format.

Return Value: This method returns the string. It is a copy of format in which any format items are replaced by the string representation of arg0.

Example:


Output
Temperature on 05/20/2020:
 14:17:32: 24.1 degrees (hi)
 03:16:10: 21.8 degrees (lo)


3. String.Format(IFormatProvider, String, Object) Method 

This method is used to replaces the format item or items in a specified string with the string representation of the corresponding object. A parameter supplies culture-specific formatting information.

Syntax:

public static string Format (IFormatProvider provider, string format, object arg0);

Parameter:

  • provider: This parameter is the object that supplies culture-specific formatting information.
  • format: This parameter is the required composite format string.
  • arg0: This parameter is the object to format.

Return Value: This method returns the string. It is a copy of format in which any format items are replaced by the string representation of arg0.

Example:


Output
Sunday, March 16, 2025 
Comment
Article Tags:

Explore