Convert Class

Definition

Converts a base data type to another base data type.

public ref class Convert abstract sealed
public ref class Convert sealed
public static class Convert
public sealed class Convert
type Convert = class
Public Class Convert
Public NotInheritable Class Convert
Inheritance
Convert

Examples

The following example demonstrates some of the conversion methods in the Convert class, including ToInt32, ToBoolean, and ToString.

Double dNumber = 23.15;

try
{
   // Returns 23
   Int32 iNumber = Convert::ToInt32( dNumber );
}
catch ( OverflowException^ ) 
{
   Console::WriteLine(
      "Overflow in Double to Int32 conversion" );
}
// Returns True
Boolean bNumber = Convert::ToBoolean( dNumber );

// Returns "23.15"
String^ strNumber = Convert::ToString( dNumber );

try
{
   // Returns '2'
   Char chrNumber = Convert::ToChar( strNumber->Substring( 0, 1 ) );
}
catch ( ArgumentNullException^ ) 
{
   Console::WriteLine(  "String is null" );
}
catch ( FormatException^ ) 
{
   Console::WriteLine(  "String length is greater than 1" );
}

// System::Console::ReadLine() returns a string and it
// must be converted.
Int32 newInteger = 0;
try
{
   Console::WriteLine(  "Enter an integer:" );
   newInteger = Convert::ToInt32( System::Console::ReadLine() );
}
catch ( ArgumentNullException^ ) 
{
   Console::WriteLine(  "String is null" );
}
catch ( FormatException^ ) 
{
   Console::WriteLine(  "String does not consist of an " +
      "optional sign followed by a series of digits" );
}
catch ( OverflowException^ ) 
{
   Console::WriteLine(  "Overflow in string to Int32 conversion" );
}

Console::WriteLine( "Your integer as a Double is {0}",
   Convert::ToDouble( newInteger ) );
double dNumber = 23.15;

try {
    // Returns 23
    int    iNumber = System.Convert.ToInt32(dNumber);
}
catch (System.OverflowException) {
    System.Console.WriteLine(
                "Overflow in double to int conversion.");
}
// Returns True
bool   bNumber = System.Convert.ToBoolean(dNumber);

// Returns "23.15"
string strNumber = System.Convert.ToString(dNumber);

try {
    // Returns '2'
    char chrNumber = System.Convert.ToChar(strNumber[0]);
}
catch (System.ArgumentNullException) {
    System.Console.WriteLine("String is null");
}
catch (System.FormatException) {
    System.Console.WriteLine("String length is greater than 1.");
}

// System.Console.ReadLine() returns a string and it
// must be converted.
int newInteger = 0;
try {
    System.Console.WriteLine("Enter an integer:");
    newInteger = System.Convert.ToInt32(
                        System.Console.ReadLine());
}
catch (System.ArgumentNullException) {
    System.Console.WriteLine("String is null.");
}
catch (System.FormatException) {
    System.Console.WriteLine("String does not consist of an " +
                    "optional sign followed by a series of digits.");
}
catch (System.OverflowException) {
    System.Console.WriteLine(
    "Overflow in string to int conversion.");
}

System.Console.WriteLine("Your integer as a double is {0}",
                         System.Convert.ToDouble(newInteger));
let dNumber = 23.15

try
    // Returns 23
    Convert.ToInt32 dNumber
    |> ignore
with :? OverflowException ->
    printfn "Overflow in double to int conversion."
// Returns True
let bNumber = System.Convert.ToBoolean dNumber

// Returns "23.15"
let strNumber = System.Convert.ToString dNumber

try
    // Returns '2'
    System.Convert.ToChar strNumber[0]
    |> ignore
with
| :? ArgumentNullException ->
    printfn "String is null"
| :? FormatException ->
    printfn "String length is greater than 1."

// System.Console.ReadLine() returns a string and it
// must be converted.
let newInteger =
    try
        printfn "Enter an integer:"
        System.Convert.ToInt32(Console.ReadLine())
    with
    | :? ArgumentNullException ->
        printfn "String is null."
        0
    | :? FormatException ->
        printfn "String does not consist of an optional sign followed by a series of digits."
        0
    | :? OverflowException ->
        printfn "Overflow in string to int conversion."
        0

printfn $"Your integer as a double is {System.Convert.ToDouble newInteger}"
Dim dNumber As Double
dNumber = 23.15

Try
   ' Returns 23
   Dim iNumber As Integer
   iNumber = System.Convert.ToInt32(dNumber)
Catch exp As System.OverflowException
   System.Console.WriteLine("Overflow in double to int conversion.")
End Try

' Returns True
Dim bNumber As Boolean
bNumber = System.Convert.ToBoolean(dNumber)

' Returns "23.15"
Dim strNumber As String
strNumber = System.Convert.ToString(dNumber)

Try
   ' Returns '2'
   Dim chrNumber As Char
   chrNumber = System.Convert.ToChar(strNumber.Chars(1))
Catch exp As System.ArgumentNullException
   System.Console.WriteLine("String is null.")
Catch exp As System.FormatException
   System.Console.WriteLine("String length is greater than 1.")
End Try

' System.Console.ReadLine() returns a string and it
' must be converted.
Dim newInteger As Integer
newInteger = 0
Try
   System.Console.WriteLine("Enter an integer:")
   newInteger = System.Convert.ToInt32(System.Console.ReadLine())
Catch exp As System.ArgumentNullException
   System.Console.WriteLine("String is null.")
Catch exp As System.FormatException
   System.Console.WriteLine("String does not consist of an " + _
       "optional sign followed by a series of digits.")
Catch exp As System.OverflowException
   System.Console.WriteLine("Overflow in string to int conversion.")
End Try

System.Console.WriteLine("Your integer as a double is {0}", _
                         System.Convert.ToDouble(newInteger))

Remarks

The static methods of the Convert class are primarily used to support conversion to and from the base data types in .NET. The supported base types are Boolean, Char, SByte, Byte, Int16, Int32, Int64, UInt16, UInt32, UInt64, Single, Double, Decimal, DateTime and String. In addition, the Convert class includes methods to support other kinds of conversions.

This article consists of the following sections:

Conversions to and from Base Types Non-Decimal Numbers Conversions from Custom Objects to Base Types Culture-Specific Formatting Information Base64 Encoding Other Common Conversions

Conversions to and from Base Types

A conversion method exists to convert every base type to every other base type. However, the actual call to a particular conversion method can produce one of five outcomes, depending on the value of the base type at run time and the target base type. These five outcomes are:

  • No conversion. This occurs when an attempt is made to convert from a type to itself (for example, by calling Convert.ToInt32(Int32) with an argument of type Int32). In this case, the method simply returns an instance of the original type.

  • An InvalidCastException. This occurs when a particular conversion is not supported. An InvalidCastException is thrown for the following conversions:

  • A FormatException. This occurs when the attempt to convert a string value to any other base type fails because the string is not in the proper format. The exception is thrown for the following conversions:

    • A string to be converted to a Boolean value does not equal Boolean.TrueString or Boolean.FalseString.

    • A string to be converted to a Char value consists of multiple characters.

    • A string to be converted to any numeric type is not recognized as a valid number.

    • A string to be converted to a DateTime is not recognized as a valid date and time value.

  • A successful conversion. For conversions between two different base types not listed in the previous outcomes, all widening conversions as well as all narrowing conversions that do not result in a loss of data will succeed and the method will return a value of the targeted base type.

  • An OverflowException. This occurs when a narrowing conversion results in a loss of data. For example, trying to convert a Int32 instance whose value is 10000 to a Byte type throws an OverflowException because 10000 is outside the range of the Byte data type.

An exception will not be thrown if the conversion of a numeric type results in a loss of precision (that is, the loss of some least significant digits). However, an exception will be thrown if the result is larger than can be represented by the particular conversion method's return value type.

For example, when a Double is converted to a Single, a loss of precision might occur but no exception is thrown. However, if the magnitude of the Double is too large to be represented by a Single, an overflow exception is thrown.

Non-Decimal Numbers

The Convert class includes static methods that you can call to convert integral values to non-decimal string representations, and to convert strings that represent non-decimal numbers to integral values. Each of these conversion methods includes a base argument that lets you specify the number system; binary (base 2), octal (base 8), and hexadecimal (base 16), as well as decimal (base 10). There is a set of methods to convert each of the CLS-compliant primitive integral types to a string, and one to convert a string to each of the primitive integral types:

The following example converts the value of Int16.MaxValue to a string in all supported numeric formats. It then converts the string value back to a Int16 value.

using namespace System;

void main()
{
   array<int>^ baseValues = { 2, 8, 10, 16 };
   Int16 value = Int16::MaxValue;
   for each (Int16 baseValue in baseValues) {
      String^ s = Convert::ToString(value, baseValue);
      Int16 value2 = Convert::ToInt16(s, baseValue);

      Console::WriteLine("{0} --> {1} (base {2}) --> {3}", 
                        value, s, baseValue, value2);
   }                     
}
// The example displays the following output:
//     32767 --> 111111111111111 (base 2) --> 32767
//     32767 --> 77777 (base 8) --> 32767
//     32767 --> 32767 (base 10) --> 32767
//     32767 --> 7fff (base 16) --> 32767
using System;

public class Example
{
   public static void Main()
   {
      int[] baseValues = { 2, 8, 10, 16 };
      short value = Int16.MaxValue;
      foreach (var baseValue in baseValues) {
         String s = Convert.ToString(value, baseValue);
         short value2 = Convert.ToInt16(s, baseValue);

         Console.WriteLine("{0} --> {1} (base {2}) --> {3}",
                           value, s, baseValue, value2);
      }
   }
}
// The example displays the following output:
//     32767 --> 111111111111111 (base 2) --> 32767
//     32767 --> 77777 (base 8) --> 32767
//     32767 --> 32767 (base 10) --> 32767
//     32767 --> 7fff (base 16) --> 32767
open System

let baseValues = [ 2; 8; 10; 16 ]
let value = Int16.MaxValue
for baseValue in baseValues do
    let s = Convert.ToString(value, baseValue)
    let value2 = Convert.ToInt16(s, baseValue)
    printfn $"{value} --> {s} (base {baseValue}) --> {value2}"

// The example displays the following output:
//     32767 --> 111111111111111 (base 2) --> 32767
//     32767 --> 77777 (base 8) --> 32767
//     32767 --> 32767 (base 10) --> 32767
//     32767 --> 7fff (base 16) --> 32767
Module Example
   Public Sub Main()
      Dim baseValues() As Integer = { 2, 8, 10, 16 }
      Dim value As Short = Int16.MaxValue
      For Each baseValue in baseValues
         Dim s As String = Convert.ToString(value, baseValue)
         Dim value2 As Short = Convert.ToInt16(s, baseValue)

         Console.WriteLine("{0} --> {1} (base {2}) --> {3}", 
                           value, s, baseValue, value2)
      Next
   End Sub
End Module
' The example displays the following output:
'     32767 --> 111111111111111 (base 2) --> 32767
'     32767 --> 77777 (base 8) --> 32767
'     32767 --> 32767 (base 10) --> 32767
'     32767 --> 7fff (base 16) --> 32767

Conversions from Custom Objects to Base Types

In addition to supporting conversions between the base types, the Convert method supports conversion of any custom type to any base type. To do this, the custom type must implement the IConvertible interface, which defines methods for converting the implementing type to each of the base types. Conversions that are not supported by a particular type should throw an InvalidCastException.

When the ChangeType method is passed a custom type as its first parameter, or when the Convert.ToType method (such as Convert.ToInt32(Object) or Convert.ToDouble(Object, IFormatProvider) is called and passed an instance of a custom type as its first parameter, the Convert method, in turn, calls the custom type's IConvertible implementation to perform the conversion. For more information, see Type Conversion in .NET.

Culture-Specific Formatting Information

All the base type conversion methods and the ChangeType method include overloads that have a parameter of type IFormatProvider. For example, the Convert.ToBoolean method has the following two overloads:

The IFormatProvider parameter can supply culture-specific formatting information to assist the conversion process. However, it is ignored by most of the base type conversion methods. It is used only by the following base type conversion methods. If a null IFormatProvider argument is passed to these methods, the CultureInfo object that represents the current culture is used.

However, any user-defined type that implements IConvertible can make use of the IFormatProvider parameter.

Base64 Encoding

Base64 encoding converts binary data to a string. Data expressed as base-64 digits can be easily conveyed over data channels that can only transmit 7-bit characters. The Convert class includes the following methods to support base64 encoding: A set of methods support converting an array of bytes to and from a String or to and from an array of Unicode characters consisting of base-64 digit characters.

Other Common Conversions

You can use other classes in the NET Framework to perform some conversions that are not supported by the static methods of the Convert class. These include:

Conversion to byte arrays The BitConverter class provides methods that convert the primitive numeric types (including Boolean) to byte arrays and from byte arrays back to primitive data types.

Character encoding and decoding The Encoding class and its derived classes (such as UnicodeEncoding and UTF8Encoding) provide methods to encode a character array or a string (that is, to convert them to a byte array in a particular encoding) and to decode an encoded byte array (that is, convert a byte array back to UTF16-encoded Unicode characters. For more information, see Character Encoding in .NET.

Fields

DBNull

A constant that represents a database column that is absent of data; that is, database null.

Methods

ChangeType(Object, Type)

Returns an object of the specified type and whose value is equivalent to the specified object.

ChangeType(Object, Type, IFormatProvider)

Returns an object of the specified type whose value is equivalent to the specified object. A parameter supplies culture-specific formatting information.

ChangeType(Object, TypeCode)

Returns an object of the specified type whose value is equivalent to the specified object.

ChangeType(Object, TypeCode, IFormatProvider)

Returns an object of the specified type whose value is equivalent to the specified object. A parameter supplies culture-specific formatting information.

FromBase64CharArray(Char[], Int32, Int32)

Converts a subset of a Unicode character array, which encodes binary data as base-64 digits, to an equivalent 8-bit unsigned integer array. Parameters specify the subset in the input array and the number of elements to convert.

FromBase64String(String)

Converts the specified string, which encodes binary data as base-64 digits, to an equivalent 8-bit unsigned integer array.

FromHexString(ReadOnlySpan<Char>)

Converts the span, which encodes binary data as hex characters, to an equivalent 8-bit unsigned integer array.

FromHexString(String)

Converts the specified string, which encodes binary data as hex characters, to an equivalent 8-bit unsigned integer array.

GetTypeCode(Object)

Returns the TypeCode for the specified object.

IsDBNull(Object)

Returns an indication whether the specified object is of type DBNull.

ToBase64CharArray(Byte[], Int32, Int32, Char[], Int32)

Converts a subset of an 8-bit unsigned integer array to an equivalent subset of a Unicode character array encoded with base-64 digits. Parameters specify the subsets as offsets in the input and output arrays, and the number of elements in the input array to convert.

ToBase64CharArray(Byte[], Int32, Int32, Char[], Int32, Base64FormattingOptions)

Converts a subset of an 8-bit unsigned integer array to an equivalent subset of a Unicode character array encoded with base-64 digits. Parameters specify the subsets as offsets in the input and output arrays, the number of elements in the input array to convert, and whether line breaks are inserted in the output array.

ToBase64String(Byte[])

Converts an array of 8-bit unsigned integers to its equivalent string representation that is encoded with base-64 digits.

ToBase64String(Byte[], Base64FormattingOptions)

Converts an array of 8-bit unsigned integers to its equivalent string representation that is encoded with base-64 digits. You can specify whether to insert line breaks in the return value.

ToBase64String(Byte[], Int32, Int32)

Converts a subset of an array of 8-bit unsigned integers to its equivalent string representation that is encoded with base-64 digits. Parameters specify the subset as an offset in the input array, and the number of elements in the array to convert.

ToBase64String(Byte[], Int32, Int32, Base64FormattingOptions)

Converts a subset of an array of 8-bit unsigned integers to its equivalent string representation that is encoded with base-64 digits. Parameters specify the subset as an offset in the input array, the number of elements in the array to convert, and whether to insert line breaks in the return value.

ToBase64String(ReadOnlySpan<Byte>, Base64FormattingOptions)

Converts the 8-bit unsigned integers inside the specified read-only span into their equivalent string representation that is encoded with base-64 digits. You can optionally specify whether to insert line breaks in the return value.

ToBoolean(Boolean)

Returns the specified Boolean value; no actual conversion is performed.

ToBoolean(Byte)

Converts the value of the specified 8-bit unsigned integer to an equivalent Boolean value.

ToBoolean(Char)

Calling this method always throws InvalidCastException.

ToBoolean(DateTime)

Calling this method always throws InvalidCastException.

ToBoolean(Decimal)

Converts the value of the specified decimal number to an equivalent Boolean value.

ToBoolean(Double)

Converts the value of the specified double-precision floating-point number to an equivalent Boolean value.

ToBoolean(Int16)

Converts the value of the specified 16-bit signed integer to an equivalent Boolean value.

ToBoolean(Int32)

Converts the value of the specified 32-bit signed integer to an equivalent Boolean value.

ToBoolean(Int64)

Converts the value of the specified 64-bit signed integer to an equivalent Boolean value.

ToBoolean(Object)

Converts the value of a specified object to an equivalent Boolean value.

ToBoolean(Object, IFormatProvider)

Converts the value of the specified object to an equivalent Boolean value, using the specified culture-specific formatting information.

ToBoolean(SByte)

Converts the value of the specified 8-bit signed integer to an equivalent Boolean value.

ToBoolean(Single)

Converts the value of the specified single-precision floating-point number to an equivalent Boolean value.

ToBoolean(String)

Converts the specified string representation of a logical value to its Boolean equivalent.

ToBoolean(String, IFormatProvider)

Converts the specified string representation of a logical value to its Boolean equivalent, using the specified culture-specific formatting information.

ToBoolean(UInt16)

Converts the value of the specified 16-bit unsigned integer to an equivalent Boolean value.

ToBoolean(UInt32)

Converts the value of the specified 32-bit unsigned integer to an equivalent Boolean value.

ToBoolean(UInt64)

Converts the value of the specified 64-bit unsigned integer to an equivalent Boolean value.

ToByte(Boolean)

Converts the specified Boolean value to the equivalent 8-bit unsigned integer.

ToByte(Byte)

Returns the specified 8-bit unsigned integer; no actual conversion is performed.

ToByte(Char)

Converts the value of the specified Unicode character to the equivalent 8-bit unsigned integer.

ToByte(DateTime)

Calling this method always throws InvalidCastException.

ToByte(Decimal)

Converts the value of the specified decimal number to an equivalent 8-bit unsigned integer.

ToByte(Double)

Converts the value of the specified double-precision floating-point number to an equivalent 8-bit unsigned integer.

ToByte(Int16)

Converts the value of the specified 16-bit signed integer to an equivalent 8-bit unsigned integer.

ToByte(Int32)

Converts the value of the specified 32-bit signed integer to an equivalent 8-bit unsigned integer.

ToByte(Int64)

Converts the value of the specified 64-bit signed integer to an equivalent 8-bit unsigned integer.

ToByte(Object)

Converts the value of the specified object to an 8-bit unsigned integer.

ToByte(Object, IFormatProvider)

Converts the value of the specified object to an 8-bit unsigned integer, using the specified culture-specific formatting information.

ToByte(SByte)

Converts the value of the specified 8-bit signed integer to an equivalent 8-bit unsigned integer.

ToByte(Single)

Converts the value of the specified single-precision floating-point number to an equivalent 8-bit unsigned integer.

ToByte(String)

Converts the specified string representation of a number to an equivalent 8-bit unsigned integer.

ToByte(String, IFormatProvider)

Converts the specified string representation of a number to an equivalent 8-bit unsigned integer, using specified culture-specific formatting information.

ToByte(String, Int32)

Converts the string representation of a number in a specified base to an equivalent 8-bit unsigned integer.

ToByte(UInt16)

Converts the value of the specified 16-bit unsigned integer to an equivalent 8-bit unsigned integer.

ToByte(UInt32)

Converts the value of the specified 32-bit unsigned integer to an equivalent 8-bit unsigned integer.

ToByte(UInt64)

Converts the value of the specified 64-bit unsigned integer to an equivalent 8-bit unsigned integer.

ToChar(Boolean)

Calling this method always throws InvalidCastException.

ToChar(Byte)

Converts the value of the specified 8-bit unsigned integer to its equivalent Unicode character.

ToChar(Char)

Returns the specified Unicode character value; no actual conversion is performed.

ToChar(DateTime)

Calling this method always throws InvalidCastException.

ToChar(Decimal)

Calling this method always throws InvalidCastException.

ToChar(Double)

Calling this method always throws InvalidCastException.

ToChar(Int16)

Converts the value of the specified 16-bit signed integer to its equivalent Unicode character.

ToChar(Int32)

Converts the value of the specified 32-bit signed integer to its equivalent Unicode character.

ToChar(Int64)

Converts the value of the specified 64-bit signed integer to its equivalent Unicode character.

ToChar(Object)

Converts the value of the specified object to a Unicode character.

ToChar(Object, IFormatProvider)

Converts the value of the specified object to its equivalent Unicode character, using the specified culture-specific formatting information.

ToChar(SByte)

Converts the value of the specified 8-bit signed integer to its equivalent Unicode character.

ToChar(Single)

Calling this method always throws InvalidCastException.

ToChar(String)

Converts the first character of a specified string to a Unicode character.

ToChar(String, IFormatProvider)

Converts the first character of a specified string to a Unicode character, using specified culture-specific formatting information.

ToChar(UInt16)

Converts the value of the specified 16-bit unsigned integer to its equivalent Unicode character.

ToChar(UInt32)

Converts the value of the specified 32-bit unsigned integer to its equivalent Unicode character.

ToChar(UInt64)

Converts the value of the specified 64-bit unsigned integer to its equivalent Unicode character.

ToDateTime(Boolean)

Calling this method always throws InvalidCastException.

ToDateTime(Byte)

Calling this method always throws InvalidCastException.

ToDateTime(Char)

Calling this method always throws InvalidCastException.

ToDateTime(DateTime)

Returns the specified DateTime object; no actual conversion is performed.

ToDateTime(Decimal)

Calling this method always throws InvalidCastException.

ToDateTime(Double)

Calling this method always throws InvalidCastException.

ToDateTime(Int16)

Calling this method always throws InvalidCastException.

ToDateTime(Int32)

Calling this method always throws InvalidCastException.

ToDateTime(Int64)

Calling this method always throws InvalidCastException.

ToDateTime(Object)

Converts the value of the specified object to a DateTime object.

ToDateTime(Object, IFormatProvider)

Converts the value of the specified object to a DateTime object, using the specified culture-specific formatting information.

ToDateTime(SByte)

Calling this method always throws InvalidCastException.

ToDateTime(Single)

Calling this method always throws InvalidCastException.

ToDateTime(String)

Converts the specified string representation of a date and time to an equivalent date and time value.

ToDateTime(String, IFormatProvider)

Converts the specified string representation of a number to an equivalent date and time, using the specified culture-specific formatting information.

ToDateTime(UInt16)

Calling this method always throws InvalidCastException.

ToDateTime(UInt32)

Calling this method always throws InvalidCastException.

ToDateTime(UInt64)

Calling this method always throws InvalidCastException.

ToDecimal(Boolean)

Converts the specified Boolean value to the equivalent decimal number.

ToDecimal(Byte)

Converts the value of the specified 8-bit unsigned integer to the equivalent decimal number.

ToDecimal(Char)

Calling this method always throws InvalidCastException.

ToDecimal(DateTime)

Calling this method always throws InvalidCastException.

ToDecimal(Decimal)

Returns the specified decimal number; no actual conversion is performed.

ToDecimal(Double)

Converts the value of the specified double-precision floating-point number to an equivalent decimal number.

ToDecimal(Int16)

Converts the value of the specified 16-bit signed integer to an equivalent decimal number.

ToDecimal(Int32)

Converts the value of the specified 32-bit signed integer to an equivalent decimal number.

ToDecimal(Int64)

Converts the value of the specified 64-bit signed integer to an equivalent decimal number.

ToDecimal(Object)

Converts the value of the specified object to an equivalent decimal number.

ToDecimal(Object, IFormatProvider)

Converts the value of the specified object to an equivalent decimal number, using the specified culture-specific formatting information.

ToDecimal(SByte)

Converts the value of the specified 8-bit signed integer to the equivalent decimal number.

ToDecimal(Single)

Converts the value of the specified single-precision floating-point number to the equivalent decimal number.

ToDecimal(String)

Converts the specified string representation of a number to an equivalent decimal number.

ToDecimal(String, IFormatProvider)

Converts the specified string representation of a number to an equivalent decimal number, using the specified culture-specific formatting information.

ToDecimal(UInt16)

Converts the value of the specified 16-bit unsigned integer to an equivalent decimal number.

ToDecimal(UInt32)

Converts the value of the specified 32-bit unsigned integer to an equivalent decimal number.

ToDecimal(UInt64)

Converts the value of the specified 64-bit unsigned integer to an equivalent decimal number.

ToDouble(Boolean)

Converts the specified Boolean value to the equivalent double-precision floating-point number.

ToDouble(Byte)

Converts the value of the specified 8-bit unsigned integer to the equivalent double-precision floating-point number.

ToDouble(Char)

Calling this method always throws InvalidCastException.

ToDouble(DateTime)

Calling this method always throws InvalidCastException.

ToDouble(Decimal)

Converts the value of the specified decimal number to an equivalent double-precision floating-point number.

ToDouble(Double)

Returns the specified double-precision floating-point number; no actual conversion is performed.

ToDouble(Int16)

Converts the value of the specified 16-bit signed integer to an equivalent double-precision floating-point number.

ToDouble(Int32)

Converts the value of the specified 32-bit signed integer to an equivalent double-precision floating-point number.

ToDouble(Int64)

Converts the value of the specified 64-bit signed integer to an equivalent double-precision floating-point number.

ToDouble(Object)

Converts the value of the specified object to a double-precision floating-point number.

ToDouble(Object, IFormatProvider)

Converts the value of the specified object to an double-precision floating-point number, using the specified culture-specific formatting information.

ToDouble(SByte)

Converts the value of the specified 8-bit signed integer to the equivalent double-precision floating-point number.

ToDouble(Single)

Converts the value of the specified single-precision floating-point number to an equivalent double-precision floating-point number.

ToDouble(String)

Converts the specified string representation of a number to an equivalent double-precision floating-point number.

ToDouble(String, IFormatProvider)

Converts the specified string representation of a number to an equivalent double-precision floating-point number, using the specified culture-specific formatting information.

ToDouble(UInt16)

Converts the value of the specified 16-bit unsigned integer to the equivalent double-precision floating-point number.

ToDouble(UInt32)

Converts the value of the specified 32-bit unsigned integer to an equivalent double-precision floating-point number.

ToDouble(UInt64)

Converts the value of the specified 64-bit unsigned integer to an equivalent double-precision floating-point number.

ToHexString(Byte[])

Converts an array of 8-bit unsigned integers to its equivalent string representation that is encoded with uppercase hex characters.

ToHexString(Byte[], Int32, Int32)

Converts a subset of an array of 8-bit unsigned integers to its equivalent string representation that is encoded with uppercase hex characters. Parameters specify the subset as an offset in the input array and the number of elements in the array to convert.

ToHexString(ReadOnlySpan<Byte>)

Converts a span of 8-bit unsigned integers to its equivalent string representation that is encoded with uppercase hex characters.

ToInt16(Boolean)

Converts the specified Boolean value to the equivalent 16-bit signed integer.

ToInt16(Byte)

Converts the value of the specified 8-bit unsigned integer to the equivalent 16-bit signed integer.

ToInt16(Char)

Converts the value of the specified Unicode character to the equivalent 16-bit signed integer.

ToInt16(DateTime)

Calling this method always throws InvalidCastException.

ToInt16(Decimal)

Converts the value of the specified decimal number to an equivalent 16-bit signed integer.

ToInt16(Double)

Converts the value of the specified double-precision floating-point number to an equivalent 16-bit signed integer.

ToInt16(Int16)

Returns the specified 16-bit signed integer; no actual conversion is performed.

ToInt16(Int32)

Converts the value of the specified 32-bit signed integer to an equivalent 16-bit signed integer.

ToInt16(Int64)

Converts the value of the specified 64-bit signed integer to an equivalent 16-bit signed integer.

ToInt16(Object)

Converts the value of the specified object to a 16-bit signed integer.

ToInt16(Object, IFormatProvider)

Converts the value of the specified object to a 16-bit signed integer, using the specified culture-specific formatting information.

ToInt16(SByte)

Converts the value of the specified 8-bit signed integer to the equivalent 16-bit signed integer.

ToInt16(Single)

Converts the value of the specified single-precision floating-point number to an equivalent 16-bit signed integer.

ToInt16(String)

Converts the specified string representation of a number to an equivalent 16-bit signed integer.

ToInt16(String, IFormatProvider)

Converts the specified string representation of a number to an equivalent 16-bit signed integer, using the specified culture-specific formatting information.

ToInt16(String, Int32)

Converts the string representation of a number in a specified base to an equivalent 16-bit signed integer.

ToInt16(UInt16)

Converts the value of the specified 16-bit unsigned integer to the equivalent 16-bit signed integer.

ToInt16(UInt32)

Converts the value of the specified 32-bit unsigned integer to an equivalent 16-bit signed integer.

ToInt16(UInt64)

Converts the value of the specified 64-bit unsigned integer to an equivalent 16-bit signed integer.

ToInt32(Boolean)

Converts the specified Boolean value to the equivalent 32-bit signed integer.

ToInt32(Byte)

Converts the value of the specified 8-bit unsigned integer to the equivalent 32-bit signed integer.

ToInt32(Char)

Converts the value of the specified Unicode character to the equivalent 32-bit signed integer.

ToInt32(DateTime)

Calling this method always throws InvalidCastException.

ToInt32(Decimal)

Converts the value of the specified decimal number to an equivalent 32-bit signed integer.

ToInt32(Double)

Converts the value of the specified double-precision floating-point number to an equivalent 32-bit signed integer.

ToInt32(Int16)

Converts the value of the specified 16-bit signed integer to an equivalent 32-bit signed integer.

ToInt32(Int32)

Returns the specified 32-bit signed integer; no actual conversion is performed.

ToInt32(Int64)

Converts the value of the specified 64-bit signed integer to an equivalent 32-bit signed integer.

ToInt32(Object)

Converts the value of the specified object to a 32-bit signed integer.

ToInt32(Object, IFormatProvider)

Converts the value of the specified object to a 32-bit signed integer, using the specified culture-specific formatting information.

ToInt32(SByte)

Converts the value of the specified 8-bit signed integer to the equivalent 32-bit signed integer.

ToInt32(Single)

Converts the value of the specified single-precision floating-point number to an equivalent 32-bit signed integer.

ToInt32(String)

Converts the specified string representation of a number to an equivalent 32-bit signed integer.

ToInt32(String, IFormatProvider)

Converts the specified string representation of a number to an equivalent 32-bit signed integer, using the specified culture-specific formatting information.

ToInt32(String, Int32)

Converts the string representation of a number in a specified base to an equivalent 32-bit signed integer.

ToInt32(UInt16)

Converts the value of the specified 16-bit unsigned integer to the equivalent 32-bit signed integer.

ToInt32(UInt32)

Converts the value of the specified 32-bit unsigned integer to an equivalent 32-bit signed integer.

ToInt32(UInt64)

Converts the value of the specified 64-bit unsigned integer to an equivalent 32-bit signed integer.

ToInt64(Boolean)

Converts the specified Boolean value to the equivalent 64-bit signed integer.

ToInt64(Byte)

Converts the value of the specified 8-bit unsigned integer to the equivalent 64-bit signed integer.

ToInt64(Char)

Converts the value of the specified Unicode character to the equivalent 64-bit signed integer.

ToInt64(DateTime)

Calling this method always throws InvalidCastException.

ToInt64(Decimal)

Converts the value of the specified decimal number to an equivalent 64-bit signed integer.

ToInt64(Double)

Converts the value of the specified double-precision floating-point number to an equivalent 64-bit signed integer.

ToInt64(Int16)

Converts the value of the specified 16-bit signed integer to an equivalent 64-bit signed integer.

ToInt64(Int32)

Converts the value of the specified 32-bit signed integer to an equivalent 64-bit signed integer.

ToInt64(Int64)

Returns the specified 64-bit signed integer; no actual conversion is performed.

ToInt64(Object)

Converts the value of the specified object to a 64-bit signed integer.

ToInt64(Object, IFormatProvider)

Converts the value of the specified object to a 64-bit signed integer, using the specified culture-specific formatting information.

ToInt64(SByte)

Converts the value of the specified 8-bit signed integer to the equivalent 64-bit signed integer.

ToInt64(Single)

Converts the value of the specified single-precision floating-point number to an equivalent 64-bit signed integer.

ToInt64(String)

Converts the specified string representation of a number to an equivalent 64-bit signed integer.

ToInt64(String, IFormatProvider)

Converts the specified string representation of a number to an equivalent 64-bit signed integer, using the specified culture-specific formatting information.

ToInt64(String, Int32)

Converts the string representation of a number in a specified base to an equivalent 64-bit signed integer.

ToInt64(UInt16)

Converts the value of the specified 16-bit unsigned integer to the equivalent 64-bit signed integer.

ToInt64(UInt32)

Converts the value of the specified 32-bit unsigned integer to an equivalent 64-bit signed integer.

ToInt64(UInt64)

Converts the value of the specified 64-bit unsigned integer to an equivalent 64-bit signed integer.

ToSByte(Boolean)

Converts the specified Boolean value to the equivalent 8-bit signed integer.

ToSByte(Byte)

Converts the value of the specified 8-bit unsigned integer to the equivalent 8-bit signed integer.

ToSByte(Char)

Converts the value of the specified Unicode character to the equivalent 8-bit signed integer.

ToSByte(DateTime)

Calling this method always throws InvalidCastException.

ToSByte(Decimal)

Converts the value of the specified decimal number to an equivalent 8-bit signed integer.

ToSByte(Double)

Converts the value of the specified double-precision floating-point number to an equivalent 8-bit signed integer.

ToSByte(Int16)

Converts the value of the specified 16-bit signed integer to the equivalent 8-bit signed integer.

ToSByte(Int32)

Converts the value of the specified 32-bit signed integer to an equivalent 8-bit signed integer.

ToSByte(Int64)

Converts the value of the specified 64-bit signed integer to an equivalent 8-bit signed integer.

ToSByte(Object)

Converts the value of the specified object to an 8-bit signed integer.

ToSByte(Object, IFormatProvider)

Converts the value of the specified object to an 8-bit signed integer, using the specified culture-specific formatting information.

ToSByte(SByte)

Returns the specified 8-bit signed integer; no actual conversion is performed.

ToSByte(Single)

Converts the value of the specified single-precision floating-point number to an equivalent 8-bit signed integer.

ToSByte(String)

Converts the specified string representation of a number to an equivalent 8-bit signed integer.

ToSByte(String, IFormatProvider)

Converts the specified string representation of a number to an equivalent 8-bit signed integer, using the specified culture-specific formatting information.

ToSByte(String, Int32)

Converts the string representation of a number in a specified base to an equivalent 8-bit signed integer.

ToSByte(UInt16)

Converts the value of the specified 16-bit unsigned integer to the equivalent 8-bit signed integer.

ToSByte(UInt32)

Converts the value of the specified 32-bit unsigned integer to an equivalent 8-bit signed integer.

ToSByte(UInt64)

Converts the value of the specified 64-bit unsigned integer to an equivalent 8-bit signed integer.

ToSingle(Boolean)

Converts the specified Boolean value to the equivalent single-precision floating-point number.

ToSingle(Byte)

Converts the value of the specified 8-bit unsigned integer to the equivalent single-precision floating-point number.

ToSingle(Char)

Calling this method always throws InvalidCastException.

ToSingle(DateTime)

Calling this method always throws InvalidCastException.

ToSingle(Decimal)

Converts the value of the specified decimal number to an equivalent single-precision floating-point number.

ToSingle(Double)

Converts the value of the specified double-precision floating-point number to an equivalent single-precision floating-point number.

ToSingle(Int16)

Converts the value of the specified 16-bit signed integer to an equivalent single-precision floating-point number.

ToSingle(Int32)

Converts the value of the specified 32-bit signed integer to an equivalent single-precision floating-point number.

ToSingle(Int64)

Converts the value of the specified 64-bit signed integer to an equivalent single-precision floating-point number.

ToSingle(Object)

Converts the value of the specified object to a single-precision floating-point number.

ToSingle(Object, IFormatProvider)

Converts the value of the specified object to an single-precision floating-point number, using the specified culture-specific formatting information.

ToSingle(SByte)

Converts the value of the specified 8-bit signed integer to the equivalent single-precision floating-point number.

ToSingle(Single)

Returns the specified single-precision floating-point number; no actual conversion is performed.

ToSingle(String)

Converts the specified string representation of a number to an equivalent single-precision floating-point number.

ToSingle(String, IFormatProvider)

Converts the specified string representation of a number to an equivalent single-precision floating-point number, using the specified culture-specific formatting information.

ToSingle(UInt16)

Converts the value of the specified 16-bit unsigned integer to the equivalent single-precision floating-point number.

ToSingle(UInt32)

Converts the value of the specified 32-bit unsigned integer to an equivalent single-precision floating-point number.

ToSingle(UInt64)

Converts the value of the specified 64-bit unsigned integer to an equivalent single-precision floating-point number.

ToString(Boolean)

Converts the specified Boolean value to its equivalent string representation.

ToString(Boolean, IFormatProvider)

Converts the specified Boolean value to its equivalent string representation.

ToString(Byte)

Converts the value of the specified 8-bit unsigned integer to its equivalent string representation.

ToString(Byte, IFormatProvider)

Converts the value of the specified 8-bit unsigned integer to its equivalent string representation, using the specified culture-specific formatting information.

ToString(Byte, Int32)

Converts the value of an 8-bit unsigned integer to its equivalent string representation in a specified base.

ToString(Char)

Converts the value of the specified Unicode character to its equivalent string representation.

ToString(Char, IFormatProvider)

Converts the value of the specified Unicode character to its equivalent string representation, using the specified culture-specific formatting information.

ToString(DateTime)

Converts the value of the specified DateTime to its equivalent string representation.

ToString(DateTime, IFormatProvider)

Converts the value of the specified DateTime to its equivalent string representation, using the specified culture-specific formatting information.

ToString(Decimal)

Converts the value of the specified decimal number to its equivalent string representation.

ToString(Decimal, IFormatProvider)

Converts the value of the specified decimal number to its equivalent string representation, using the specified culture-specific formatting information.

ToString(Double)

Converts the value of the specified double-precision floating-point number to its equivalent string representation.

ToString(Double, IFormatProvider)

Converts the value of the specified double-precision floating-point number to its equivalent string representation.

ToString(Int16)

Converts the value of the specified 16-bit signed integer to its equivalent string representation.

ToString(Int16, IFormatProvider)

Converts the value of the specified 16-bit signed integer to its equivalent string representation, using the specified culture-specific formatting information.

ToString(Int16, Int32)

Converts the value of a 16-bit signed integer to its equivalent string representation in a specified base.

ToString(Int32)

Converts the value of the specified 32-bit signed integer to its equivalent string representation.

ToString(Int32, IFormatProvider)

Converts the value of the specified 32-bit signed integer to its equivalent string representation, using the specified culture-specific formatting information.

ToString(Int32, Int32)

Converts the value of a 32-bit signed integer to its equivalent string representation in a specified base.

ToString(Int64)

Converts the value of the specified 64-bit signed integer to its equivalent string representation.

ToString(Int64, IFormatProvider)

Converts the value of the specified 64-bit signed integer to its equivalent string representation, using the specified culture-specific formatting information.

ToString(Int64, Int32)

Converts the value of a 64-bit signed integer to its equivalent string representation in a specified base.

ToString(Object)

Converts the value of the specified object to its equivalent string representation.

ToString(Object, IFormatProvider)

Converts the value of the specified object to its equivalent string representation using the specified culture-specific formatting information.

ToString(SByte)

Converts the value of the specified 8-bit signed integer to its equivalent string representation.

ToString(SByte, IFormatProvider)

Converts the value of the specified 8-bit signed integer to its equivalent string representation, using the specified culture-specific formatting information.

ToString(Single)

Converts the value of the specified single-precision floating-point number to its equivalent string representation.

ToString(Single, IFormatProvider)

Converts the value of the specified single-precision floating-point number to its equivalent string representation, using the specified culture-specific formatting information.

ToString(String)

Returns the specified string instance; no actual conversion is performed.

ToString(String, IFormatProvider)

Returns the specified string instance; no actual conversion is performed.

ToString(UInt16)

Converts the value of the specified 16-bit unsigned integer to its equivalent string representation.

ToString(UInt16, IFormatProvider)

Converts the value of the specified 16-bit unsigned integer to its equivalent string representation, using the specified culture-specific formatting information.

ToString(UInt32)

Converts the value of the specified 32-bit unsigned integer to its equivalent string representation.

ToString(UInt32, IFormatProvider)

Converts the value of the specified 32-bit unsigned integer to its equivalent string representation, using the specified culture-specific formatting information.

ToString(UInt64)

Converts the value of the specified 64-bit unsigned integer to its equivalent string representation.

ToString(UInt64, IFormatProvider)

Converts the value of the specified 64-bit unsigned integer to its equivalent string representation, using the specified culture-specific formatting information.

ToUInt16(Boolean)

Converts the specified Boolean value to the equivalent 16-bit unsigned integer.

ToUInt16(Byte)

Converts the value of the specified 8-bit unsigned integer to the equivalent 16-bit unsigned integer.

ToUInt16(Char)

Converts the value of the specified Unicode character to the equivalent 16-bit unsigned integer.

ToUInt16(DateTime)

Calling this method always throws InvalidCastException.

ToUInt16(Decimal)

Converts the value of the specified decimal number to an equivalent 16-bit unsigned integer.

ToUInt16(Double)

Converts the value of the specified double-precision floating-point number to an equivalent 16-bit unsigned integer.

ToUInt16(Int16)

Converts the value of the specified 16-bit signed integer to the equivalent 16-bit unsigned integer.

ToUInt16(Int32)

Converts the value of the specified 32-bit signed integer to an equivalent 16-bit unsigned integer.

ToUInt16(Int64)

Converts the value of the specified 64-bit signed integer to an equivalent 16-bit unsigned integer.

ToUInt16(Object)

Converts the value of the specified object to a 16-bit unsigned integer.

ToUInt16(Object, IFormatProvider)

Converts the value of the specified object to a 16-bit unsigned integer, using the specified culture-specific formatting information.

ToUInt16(SByte)

Converts the value of the specified 8-bit signed integer to the equivalent 16-bit unsigned integer.

ToUInt16(Single)

Converts the value of the specified single-precision floating-point number to an equivalent 16-bit unsigned integer.

ToUInt16(String)

Converts the specified string representation of a number to an equivalent 16-bit unsigned integer.

ToUInt16(String, IFormatProvider)

Converts the specified string representation of a number to an equivalent 16-bit unsigned integer, using the specified culture-specific formatting information.

ToUInt16(String, Int32)

Converts the string representation of a number in a specified base to an equivalent 16-bit unsigned integer.

ToUInt16(UInt16)

Returns the specified 16-bit unsigned integer; no actual conversion is performed.

ToUInt16(UInt32)

Converts the value of the specified 32-bit unsigned integer to an equivalent 16-bit unsigned integer.

ToUInt16(UInt64)

Converts the value of the specified 64-bit unsigned integer to an equivalent 16-bit unsigned integer.

ToUInt32(Boolean)

Converts the specified Boolean value to the equivalent 32-bit unsigned integer.

ToUInt32(Byte)

Converts the value of the specified 8-bit unsigned integer to the equivalent 32-bit unsigned integer.

ToUInt32(Char)

Converts the value of the specified Unicode character to the equivalent 32-bit unsigned integer.

ToUInt32(DateTime)

Calling this method always throws InvalidCastException.

ToUInt32(Decimal)

Converts the value of the specified decimal number to an equivalent 32-bit unsigned integer.

ToUInt32(Double)

Converts the value of the specified double-precision floating-point number to an equivalent 32-bit unsigned integer.

ToUInt32(Int16)

Converts the value of the specified 16-bit signed integer to the equivalent 32-bit unsigned integer.

ToUInt32(Int32)

Converts the value of the specified 32-bit signed integer to an equivalent 32-bit unsigned integer.

ToUInt32(Int64)

Converts the value of the specified 64-bit signed integer to an equivalent 32-bit unsigned integer.

ToUInt32(Object)

Converts the value of the specified object to a 32-bit unsigned integer.

ToUInt32(Object, IFormatProvider)

Converts the value of the specified object to a 32-bit unsigned integer, using the specified culture-specific formatting information.

ToUInt32(SByte)

Converts the value of the specified 8-bit signed integer to the equivalent 32-bit unsigned integer.

ToUInt32(Single)

Converts the value of the specified single-precision floating-point number to an equivalent 32-bit unsigned integer.

ToUInt32(String)

Converts the specified string representation of a number to an equivalent 32-bit unsigned integer.

ToUInt32(String, IFormatProvider)

Converts the specified string representation of a number to an equivalent 32-bit unsigned integer, using the specified culture-specific formatting information.

ToUInt32(String, Int32)

Converts the string representation of a number in a specified base to an equivalent 32-bit unsigned integer.

ToUInt32(UInt16)

Converts the value of the specified 16-bit unsigned integer to the equivalent 32-bit unsigned integer.

ToUInt32(UInt32)

Returns the specified 32-bit unsigned integer; no actual conversion is performed.

ToUInt32(UInt64)

Converts the value of the specified 64-bit unsigned integer to an equivalent 32-bit unsigned integer.

ToUInt64(Boolean)

Converts the specified Boolean value to the equivalent 64-bit unsigned integer.

ToUInt64(Byte)

Converts the value of the specified 8-bit unsigned integer to the equivalent 64-bit unsigned integer.

ToUInt64(Char)

Converts the value of the specified Unicode character to the equivalent 64-bit unsigned integer.

ToUInt64(DateTime)

Calling this method always throws InvalidCastException.

ToUInt64(Decimal)

Converts the value of the specified decimal number to an equivalent 64-bit unsigned integer.

ToUInt64(Double)

Converts the value of the specified double-precision floating-point number to an equivalent 64-bit unsigned integer.

ToUInt64(Int16)

Converts the value of the specified 16-bit signed integer to the equivalent 64-bit unsigned integer.

ToUInt64(Int32)

Converts the value of the specified 32-bit signed integer to an equivalent 64-bit unsigned integer.

ToUInt64(Int64)

Converts the value of the specified 64-bit signed integer to an equivalent 64-bit unsigned integer.

ToUInt64(Object)

Converts the value of the specified object to a 64-bit unsigned integer.

ToUInt64(Object, IFormatProvider)

Converts the value of the specified object to a 64-bit unsigned integer, using the specified culture-specific formatting information.

ToUInt64(SByte)

Converts the value of the specified 8-bit signed integer to the equivalent 64-bit unsigned integer.

ToUInt64(Single)

Converts the value of the specified single-precision floating-point number to an equivalent 64-bit unsigned integer.

ToUInt64(String)

Converts the specified string representation of a number to an equivalent 64-bit unsigned integer.

ToUInt64(String, IFormatProvider)

Converts the specified string representation of a number to an equivalent 64-bit unsigned integer, using the specified culture-specific formatting information.

ToUInt64(String, Int32)

Converts the string representation of a number in a specified base to an equivalent 64-bit unsigned integer.

ToUInt64(UInt16)

Converts the value of the specified 16-bit unsigned integer to the equivalent 64-bit unsigned integer.

ToUInt64(UInt32)

Converts the value of the specified 32-bit unsigned integer to an equivalent 64-bit unsigned integer.

ToUInt64(UInt64)

Returns the specified 64-bit unsigned integer; no actual conversion is performed.

TryFromBase64Chars(ReadOnlySpan<Char>, Span<Byte>, Int32)

Tries to convert the specified span containing a string representation that is encoded with base-64 digits into a span of 8-bit unsigned integers.

TryFromBase64String(String, Span<Byte>, Int32)

Tries to convert the specified string representation that is encoded with base-64 digits into a span of 8-bit unsigned integers.

TryToBase64Chars(ReadOnlySpan<Byte>, Span<Char>, Int32, Base64FormattingOptions)

Tries to convert the 8-bit unsigned integers inside the specified read-only span into their equivalent string representation that is encoded with base-64 digits. You can optionally specify whether to insert line breaks in the return value.

Applies to

See also