Mono Class Library: System.String Overview | MembersSystem.String.Format Method |
Replaces the format specification in a specified string with the textual equivalent of the value of a corresponding object instance in a specified array. [Edit]
|
A string containing a copy of format in which the format specifications have been replaced by the string equivalent of the corresponding instances of object in args. [Edit]
Type Reason ArgumentNullException format or args is a null reference. [Edit] FormatException format is invalid.
-or-
The number indicating an argument to be formatted is less than zero, or greater than or equal to the length of the args array.
[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(string, object)( null, format, args ). 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 winning numbers were {0:000} {1:000} {2:000} {3:000} {4:000} today.", 5, 10, 11, 37, 42) ); Console.WriteLine( "The winning numbers were {0, -6}{1, -6}{2, -6}{3, -6}{4, -6} today.", 5, 10, 11, 37, 42 ); } }The output is
Example The winning numbers were 005 010 011 037 042 today. The winning numbers were 5 10 11 37 42 today.
Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0