Connectivity Software User's Guide and Reference
ToString(IFormattable,String) Method



OpcLabs.BaseLibPrimitives Assembly > OpcLabs.BaseLib.Extensions Namespace > IFormattableExtension Class > ToString Method : ToString(IFormattable,String) Method
Provides functionality to format the value of an object into a string representation.

The value of this parameter cannot be null (Nothing in Visual Basic).

A standard or custom format string (see Remarks).

The value of this parameter can be null (Nothing in Visual Basic).

Converts the value of the current object to its equivalent string representation using the specified format.
Syntax
'Declaration
 
<ExtensionAttribute()>
<JetBrains.Annotations.NotNullAttribute()>
Public Overloads Shared Function ToString( _
   ByVal formattable As IFormattable, _
   ByVal format As String _
) As String
'Usage
 
Dim formattable As IFormattable
Dim format As String
Dim value As String
 
value = IFormattableExtension.ToString(formattable, format)
[Extension()]
[JetBrains.Annotations.NotNull()]
public static string ToString( 
   IFormattable formattable,
   string format
)
[Extension()]
[JetBrains.Annotations.NotNull()]
public:
static String^ ToString( 
   IFormattable^ formattable,
   String^ format
) 

Parameters

formattable
Provides functionality to format the value of an object into a string representation.

The value of this parameter cannot be null (Nothing in Visual Basic).

format
A standard or custom format string (see Remarks).

The value of this parameter can be null (Nothing in Visual Basic).

Return Value

A string representation of value of the current object as specified by format.

This method never returns null (Nothing in Visual Basic).

Remarks

The format parameter should contain either a standard format specifier or a custom format pattern that defines the format of the returned string. If format is null or an empty string, the general format specifier, 'G', is used.

This method uses formatting information derived from the current culture.

This is an extension method (info: C#, VB.NET). In languages that have support for extensions methods (such as C# and VB.NET), you can use the extension method as if it were a regular method on the object that is its first parameter. In other languages (such as with Python.NET), you will call the extension as a static method, and pass it the object on which it acts as its first parameter.

Requirements

Target Platforms: .NET Framework: Windows 10 (selected versions), Windows 11 (selected versions), Windows Server 2016, Windows Server 2022; .NET: Linux, macOS, Microsoft Windows

See Also