C# String Format(String, Object)
Description
String Format(String, Object)
replaces one or more format
items in a specified string with the string representation of a specified
object.
Syntax
String.Format(String, Object)
has the following syntax.
public static string Format(
string format,
Object arg0
)
Parameters
String.Format(String, Object)
has the following parameters.
format
- A composite format string.arg0
- The object to format.
Returns
String.Format(String, Object)
method returns A copy of format in which any format items are replaced by the string representation
of arg0.
Example
The following code shows how to use
String.Format(String, Object)
method.
/* w w w . j a v 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.