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 three specified object instances. [Edit]
|
A string containing a copy of format in which the first, second, and third format specifications have been replaced by the string equivalent of arg0, arg1, and arg2. [Edit]
Type Reason ArgumentNullException format 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 number of provided objects to be formatted (3).
[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, arg1, arg2} ). 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 temperature today oscillated between {0:###} and {1:###} degrees. The average temperature was {2:000} degrees.", 78, 100, 91)); Console.WriteLine("The temperature today oscillated between {0, 4} and {1, 4} degrees. The average temperature was {2, 4} degrees.", 78, 100, 91); } }The output is
Example The temperature today oscillated between 78 and 100 degrees. The average temperature was 091 degrees. The temperature today oscillated between 78 and 100 degrees. The average temperature was 91 degrees.
Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0