C# String Format(String, Object, Object)
Description
String Format(String, Object, Object)
replaces the
format items in a specified string with the string representation of two
specified objects.
Syntax
String.Format(String, Object, Object)
has the following syntax.
public static string Format(
string format,//w w w. j a v a2 s .co m
Object arg0,
Object arg1
)
Parameters
String.Format(String, Object, Object)
has the following parameters.
format
- A composite format string.arg0
- The first object to format.arg1
- The second object to format.
Returns
String.Format(String, Object, Object)
method returns A copy of format in which format items are replaced by the string representations
of arg0 and arg1.
Example
The following code shows how to use
String.Format(String, Object, Object)
method.
//from www.j av a 2 s. c o m
using System;
public class MainClass{
public static void Main(String[] argv){
double temperature = 68.3;
string result = String.Format("At {0:t} on {0:D}, the temperature was {1:F1} degrees Fahrenheit.",
DateTime.Now, temperature);
Console.WriteLine(temperature);
}
}
The code above generates the following result.