C# String Format(String, Object[]) Array
Description
String Format(String, Object[])
replaces the format
item in a specified string with the string representation of a corresponding
object in a specified array.
Syntax
String.Format(String, Object[])
has the following syntax.
public static string Format(
string format,
params Object[] args
)
Parameters
String.Format(String, Object[])
has the following parameters.
format
- A composite format string.args
- An object array that contains zero or more objects to format.
Returns
String.Format(String, Object[])
method returns A copy of format in which the format items have been replaced by the string
representation of the corresponding objects in args.
Example
The following code shows how to use
String.Format(String, Object[])
method.
/*from ww w . j a v a 2 s .co 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.",
new Object[] { DateTime.Now, temperature });
Console.WriteLine(temperature);
}
}
The code above generates the following result.