Mono Class Library: System.String Overview | MembersSystem.String.Format Method |
Replaces the format specification in a provided string with a specified textual equivalent of the value of a specified object instance. [Edit]
|
A copy of format in which the first format specification has been replaced by the formatted string equivalent of the arg0. [Edit]
Type Reason ArgumentNullException format is a null reference. [Edit] FormatException The format specification in format is invalid.
-or-
The number indicating an argument to be formatted is less than zero, or greater than or equal to the number of provided objects to be formatted (1).
[Edit]
If an object referenced in the format string is a null reference, an empty string is used in its place.
Note: This version of string.Format(string, object) is equivalent to String.Format( null , format, new Object[] {arg0} ). For more information on the format specification see the string class overview.[Edit]
The following example demonstrates the string.Format(string, object) method.
C# Example using System; public class StringFormat { public static void Main() { Console.WriteLine(String.Format("The high temperature today was {0:###} degrees.", 88)); Console.WriteLine("The museum had {0,-6} visitors today.", 88); } }The output is
Example The high temperature today was 88 degrees. The museum had 88 visitors today.
Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0