![]() |
VOOZH | about |
In C#, Format() is a string method. 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.
This method can be overloaded by passing different type of arguments to it. There are total 8 methods in the overload list of the Format() method in which 6 are discussed in Set-1 and Set-2, and remaining are discussed in this article.
This method is used to replaces the format items in a string with the string representation of two specified objects. A parameter supplies culture-specific formatting information.
Syntax :
public static string Format (IFormatProvider provider, string format, object arg0, object arg1);
Parameter: This method has the following parameters:
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 first object to format.
arg1: This parameter is the second object to format.
Return Value: This method returns the string. It is a copy of format in which the format items are replaced by the string representation of arg0 and arg1.
Example :
Output:
Value: 169 NOT of Value: -170
This method is used to replaces the format items in a string with the string representation of three specified objects. An parameter supplies culture-specific formatting information.
Syntax :
public static string Format (IFormatProvider provider, string format, object arg0, object arg1, object arg2);
Parameter: This method has the following parameters:
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 first object to format.
arg1: This parameter is the second object to format.
arg2: This parameter is the third object to format.
Return Value: This method returns the string. It is a copy of format in which the format items are replaced by the string representation of arg0, arg1 and arg2.
Example :
Output:
Value 1: 169 Value 2: 961 Sum of Values : 1130