![]() |
VOOZH | about |
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.
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.
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:
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:
Tuesday, 11 March 2025
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:
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:
Temperature on 05/20/2020: 14:17:32: 24.1 degrees (hi) 03:16:10: 21.8 degrees (lo)
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:
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:
Sunday, March 16, 2025