C# StringBuilder AppendFormat(String, Object[]) Array
Description
StringBuilder AppendFormat(String, Object[])
Appends
the string returned by processing a composite format string, which contains
zero or more format items, to this instance. Each format item is replaced
by the string representation of a corresponding argument in a parameter
array.
Syntax
StringBuilder.AppendFormat(String, Object[])
has the following syntax.
public StringBuilder AppendFormat(
string format,
params Object[] args
)
Parameters
StringBuilder.AppendFormat(String, Object[])
has the following parameters.
format
- A composite format string (see Remarks).args
- An array of objects to format.
Returns
StringBuilder.AppendFormat(String, Object[])
method returns A reference to this instance with format appended. Each format item in format
is replaced by the string representation of the corresponding object argument.
Example
The following example demonstrates the AppendFormat method.
// www .j a v a2 s . c om
using System;
using System.Text;
using System.Globalization;
class Sample
{
public static void Main()
{
StringBuilder sb = new StringBuilder();
object[] var4 = { 3, 4.4, 'X' };
sb.AppendFormat("4) {0}, {1}, {2}", var4);
Console.WriteLine(sb.ToString());
}
}
The code above generates the following result.