String.Format Method
Replaces each format item in a specified String with the text equivalent of a corresponding object's value.
Overload List
Replaces the format item in a specified String with the text equivalent of the value of a specified Object instance.
Supported by the .NET Compact Framework.
[Visual Basic] Overloads Public Shared Function Format(String, Object) As String
[C#] public static string Format(string, object);
[C++] public: static String* Format(String*, Object*);
[JScript] public static function Format(String, Object) : String;
Replaces the format item in a specified String with the text equivalent of the value of a corresponding Object instance in a specified array.
Supported by the .NET Compact Framework.
[Visual Basic] Overloads Public Shared Function Format(String, ParamArray Object()) As String
[C#] public static string Format(string, params object[]);
[C++] public: static String* Format(String*, Object[]);
[JScript] public static function Format(String, Object[]) : String;
Replaces the format item in a specified String with the text equivalent of the value of a corresponding Object instance in a specified array. A specified parameter supplies culture-specific formatting information.
Supported by the .NET Compact Framework.
[Visual Basic] Overloads Public Shared Function Format(IFormatProvider, String, ParamArray Object()) As String
[C#] public static string Format(IFormatProvider, string, params object[]);
[C++] public: static String* Format(IFormatProvider*, String*, Object[]);
[JScript] public static function Format(IFormatProvider, String, Object[]) : String;
Replaces the format item in a specified String with the text equivalent of the value of two specified Object instances.
Supported by the .NET Compact Framework.
[Visual Basic] Overloads Public Shared Function Format(String, Object, Object) As String
[C#] public static string Format(string, object, object);
[C++] public: static String* Format(String*, Object*, Object*);
[JScript] public static function Format(String, Object, Object) : String;
Replaces the format item in a specified String with the text equivalent of the value of three specified Object instances.
Supported by the .NET Compact Framework.
[Visual Basic] Overloads Public Shared Function Format(String, Object, Object, Object) As String
[C#] public static string Format(string, object, object, object);
[C++] public: static String* Format(String*, Object*, Object*, Object*);
[JScript] public static function Format(String, Object, Object, Object) : String;
Example
[Visual Basic, C#, C++] The following example demonstrates formatting multiple values.
[Visual Basic, C#, C++] Note This example shows how to use one of the overloaded versions of Format. For other examples that might be available, see the individual overload topics.
[Visual Basic] <Serializable()> Public Class LogicalCallContextData Implements ILogicalThreadAffinative Private _nAccesses As Integer Private _principal As IPrincipal Public ReadOnly Property numOfAccesses() As String Get Return [String].Format("The identity of {0} has been accessed {1} times.", _principal.Identity.Name, _nAccesses) End Get End Property Public ReadOnly Property Principal() As IPrincipal Get _nAccesses += 1 Return _principal End Get End Property Public Sub New(p As IPrincipal) _nAccesses = 0 _principal = p End Sub 'New End Class 'LogicalCallContextData [C#] [Serializable] public class LogicalCallContextData : ILogicalThreadAffinative { int _nAccesses; IPrincipal _principal; public string numOfAccesses { get { return String.Format("The identity of {0} has been accessed {1} times.", _principal.Identity.Name, _nAccesses); } } public IPrincipal Principal { get { _nAccesses ++; return _principal; } } public LogicalCallContextData(IPrincipal p) { _nAccesses = 0; _principal = p; } } [C++] [Serializable] public __gc class LogicalCallContextData : public ILogicalThreadAffinative { int _nAccesses; IPrincipal* _principal; public: __property String* get_numOfAccesses() { return String::Format(S"The identity of {0} has been accessed {1} times.", _principal->Identity->Name, __box(_nAccesses)); } public: __property IPrincipal* get_Principal() { _nAccesses ++; return _principal; } public: LogicalCallContextData(IPrincipal* p) { _nAccesses = 0; _principal = p; } };
[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button
in the upper-left corner of the page.