Class Convert
Converts a base data type to another base data type.
Inherited Members
Namespace: System
Assembly: mscorlib.dll
Syntax
public static class Convert
Methods
| Improve this Doc View SourceFromBase64CharArray(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.
Declaration
public static byte[] FromBase64CharArray(char[] inArray, int offset, int length)
Parameters
Type | Name | Description |
---|---|---|
Char[] | inArray | A Unicode character array. |
Int32 | offset | A position within |
Int32 | length | The number of elements in |
Returns
Type | Description |
---|---|
Byte[] | An array of 8-bit unsigned integers equivalent to |
FromBase64String(String)
Converts the specified string, which encodes binary data as base-64 digits, to an equivalent 8-bit unsigned integer array.
Declaration
public static extern byte[] FromBase64String(string inString)
Parameters
Type | Name | Description |
---|---|---|
String | inString | The string to convert. |
Returns
Type | Description |
---|---|
Byte[] | An array of 8-bit unsigned integers that is equivalent to |
Remarks
s is composed of base-64 digits, white-space characters, and trailing padding characters. The base-64 digits in ascending order from zero are the uppercase characters "A" to "Z", lowercase characters "a" to "z", numerals "0" to "9", and the symbols "+" and "/". The white-space characters, and their Unicode names and hexadecimal code points, are tab(CHARACTER TABULATION, U+0009), newline(LINE FEED, U+000A), carriage return (CARRIAGE RETURN, U+000D), and blank(SPACE, U+0020). An arbitrary number of white-space characters can appear in s because all white-space characters are ignored. The valueless character, "=", is used for trailing padding. The end of s can consist of zero, one, or two padding characters.
ToBase64String(Byte[])
Converts an array of 8-bit unsigned integers to its equivalent String representation encoded with base 64 digits.
Declaration
public static string ToBase64String(byte[] inArray)
Parameters
Type | Name | Description |
---|---|---|
Byte[] | inArray | An array of 8-bit unsigned integers. |
Returns
Type | Description |
---|---|
String | The String representation, in base 64, of the contents of |
ToBase64String(Byte[], Base64FormattingOptions)
Converts an array of 8-bit unsigned integers to its equivalent string representation that is encoded with base-64 digits. A parameter specifies whether to insert line breaks in the return value.
Declaration
public static string ToBase64String(byte[] inArray, Base64FormattingOptions options)
Parameters
Type | Name | Description |
---|---|---|
Byte[] | inArray | An array of 8-bit unsigned integers. |
Base64FormattingOptions | options | InsertLineBreaks to insert a line break every 76 characters, or None to not insert line breaks. |
Returns
Type | Description |
---|---|
String | The string representation in base 64 of the elements in |
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.
Declaration
public static string ToBase64String(byte[] inArray, int offset, int length)
Parameters
Type | Name | Description |
---|---|---|
Byte[] | inArray | An array of 8-bit unsigned integers. |
Int32 | offset | An offset in |
Int32 | length | The number of elements of |
Returns
Type | Description |
---|---|
String | The string representation in base 64 of |
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.
Declaration
public static string ToBase64String(byte[] inArray, int offset, int length, Base64FormattingOptions options)
Parameters
Type | Name | Description |
---|---|---|
Byte[] | inArray | An array of 8-bit unsigned integers. |
Int32 | offset | An offset in |
Int32 | length | The number of elements of |
Base64FormattingOptions | options | cref="System.InsertLineBreaks" to insert a line break every 76 characters, or None to not insert line breaks. |
Returns
Type | Description |
---|---|
String | The string representation in base 64 of |
ToBoolean(Byte)
Converts the value of the specified 8-bit unsigned integer to an equivalent Boolean value.
Declaration
public static bool ToBoolean(byte value)
Parameters
Type | Name | Description |
---|---|---|
Byte | value | The 8-bit unsigned integer to convert. |
Returns
Type | Description |
---|---|
Boolean | true if |
ToByte(Boolean)
Converts the specified Boolean value to the equivalent 8-bit unsigned integer.
Declaration
public static byte ToByte(bool value)
Parameters
Type | Name | Description |
---|---|---|
Boolean | value | The Boolean value to convert. |
Returns
Type | Description |
---|---|
Byte | The number 1 if |
ToByte(String, Int32)
Converts the string representation of a number in a specified base to an equivalent 8-bit unsigned integer.
Declaration
public static byte ToByte(string value, int fromBase = 10)
Parameters
Type | Name | Description |
---|---|---|
String | value | A string that contains the number to convert. |
Int32 | fromBase | The base of the number in |
Returns
Type | Description |
---|---|
Byte | A 8-bit unsigned integer that is equivalent to the number in |
Remarks
The .NET nanoFramework implementation of this method may provide only a subset of the equivalent .NET method.
Conversion will work with any base on most platforms. If a conversion is not supported, it will throw a PlatformNotSupportedException.
Note that base 10 and base 16 are always supported.
Exceptions
Type | Condition |
---|---|
ArgumentException |
-or-
|
PlatformNotSupportedException | If the platform doesn't support converting from bases other than 10 or 16. |
ToChar(UInt16)
Converts the value of the specified 16-bit unsigned integer to its equivalent Unicode character.
Declaration
[CLSCompliant(false)]
public static char ToChar(ushort value)
Parameters
Type | Name | Description |
---|---|---|
UInt16 | value | The 16-bit unsigned integer to convert. |
Returns
Type | Description |
---|---|
Char | A Unicode character that is equivalent to value. |
ToDateTime(String)
Converts the specified string representation of a date and time to an equivalent date and time value.
Declaration
public static DateTime ToDateTime(string value)
Parameters
Type | Name | Description |
---|---|---|
String | value | The string representation of a date and time. |
Returns
Type | Description |
---|---|
DateTime | The date and time equivalent of the value of |
Remarks
If value
is not null, the return value is the result of invoking the Parse(String) method on value using the formatting information of the Invariant Culture. The value
argument must contain the representation of a date and time in one of the formats described in the DateTimeFormatInfo topic. If value
is null, the method returns MinValue.
This method tries to parse value
completely and avoid throwing a FormatException. It completes missing month, day, and year information with the current date. If value contains only a date and no time, this method assumes a time of midnight. Any leading, inner, or trailing white-space characters in value are ignored.
If you prefer not to handle an exception if the conversion fails, you can call the TryParse(String, out DateTime) method instead. It returns a Boolean value that indicates whether the conversion succeeded or failed.
Exceptions
Type | Condition |
---|---|
FormatException |
|
ToDouble(String)
Converts the specified string representation of a number to an equivalent double-precision floating-point number.
Declaration
public static double ToDouble(string value)
Parameters
Type | Name | Description |
---|---|---|
String | value | A string that contains the number to convert. |
Returns
Type | Description |
---|---|
Double | A double-precision floating-point number that is equivalent to the number in value, or 0 (zero) if value is null. |
ToInt16(String, Int32)
Converts the string representation of a number in a specified base to an equivalent 16-bit signed integer.
Declaration
public static short ToInt16(string value, int fromBase = 10)
Parameters
Type | Name | Description |
---|---|---|
String | value | A string that contains the number to convert. |
Int32 | fromBase | The base of the number in |
Returns
Type | Description |
---|---|
Int16 | A 16-bit signed integer that is equivalent to the number in |
Remarks
The .NET nanoFramework implementation of this method may provide only a subset of the equivalent .NET method.
Conversion will work with any base on most platforms. If a conversion is not supported, it will throw a PlatformNotSupportedException.
Note that base 10 and base 16 are always supported.
Exceptions
Type | Condition |
---|---|
ArgumentException |
-or-
|
PlatformNotSupportedException | If the platform doesn't support converting from bases other than 10 or 16. |
ToInt32(String, Int32)
Converts the string representation of a number in a specified base to an equivalent 32-bit signed integer.
Declaration
public static int ToInt32(string value, int fromBase = 10)
Parameters
Type | Name | Description |
---|---|---|
String | value | A string that contains the number to convert. |
Int32 | fromBase | The base of the number in |
Returns
Type | Description |
---|---|
Int32 | A 32-bit signed integer that is equivalent to the number in |
Remarks
The .NET nanoFramework implementation of this method may provide only a subset of the equivalent .NET method.
Conversion will work with any base on most platforms. If a conversion is not supported, it will throw a PlatformNotSupportedException.
Note that base 10 and base 16 are always supported.
Exceptions
Type | Condition |
---|---|
ArgumentException |
-or-
|
PlatformNotSupportedException | If the platform doesn't support converting from bases other than 10 or 16. |
ToInt64(String, Int32)
Converts the string representation of a number in a specified base to an equivalent 64-bit signed integer.
Declaration
public static long ToInt64(string value, int fromBase = 10)
Parameters
Type | Name | Description |
---|---|---|
String | value | A string that contains the number to convert. |
Int32 | fromBase | The base of the number in |
Returns
Type | Description |
---|---|
Int64 | A 64-bit signed integer that is equivalent to the number in |
Remarks
The .NET nanoFramework implementation of this method may provide only a subset of the equivalent .NET method.
Conversion will work with any base on most platforms. If a conversion is not supported, it will throw a PlatformNotSupportedException.
Note that base 10 and base 16 are always supported.
Exceptions
Type | Condition |
---|---|
ArgumentException |
-or-
|
PlatformNotSupportedException | If the platform doesn't support converting from bases other than 10 or 16. |
ToSByte(String, Int32)
Converts the string representation of a number in a specified base to an equivalent 8-bit signed integer.
Declaration
[CLSCompliant(false)]
public static sbyte ToSByte(string value, int fromBase = 10)
Parameters
Type | Name | Description |
---|---|---|
String | value | A string that contains the number to convert. |
Int32 | fromBase | The base of the number in |
Returns
Type | Description |
---|---|
SByte | A 8-bit signed integer that is equivalent to the number in |
Remarks
The .NET nanoFramework implementation of this method may provide only a subset of the equivalent .NET method.
Conversion will work with any base on most platforms. If a conversion is not supported, it will throw a PlatformNotSupportedException.
Note that base 10 and base 16 are always supported.
Exceptions
Type | Condition |
---|---|
ArgumentException |
-or-
|
PlatformNotSupportedException | If the platform doesn't support converting from bases other than 10 or 16. |
ToSingle(String)
Converts the specified string representation of a number to an equivalent single-precision floating-point number.
Declaration
public static float ToSingle(string value)
Parameters
Type | Name | Description |
---|---|---|
String | value | A string that contains the number to convert. |
Returns
Type | Description |
---|---|
Single | A single-precision floating-point number that is equivalent to the number in value, or 0 (zero) if value is null. |
ToUInt16(String, Int32)
Converts the string representation of a number in a specified base to an equivalent 16-bit unsigned integer.
Declaration
[CLSCompliant(false)]
public static ushort ToUInt16(string value, int fromBase = 10)
Parameters
Type | Name | Description |
---|---|---|
String | value | A string that contains the number to convert. |
Int32 | fromBase | The base of the number in |
Returns
Type | Description |
---|---|
UInt16 | A 16-bit unsigned integer that is equivalent to the number in |
Remarks
The .NET nanoFramework implementation of this method may provide only a subset of the equivalent .NET method.
Conversion will work with any base on most platforms. If a conversion is not supported, it will throw a PlatformNotSupportedException.
Note that base 10 and base 16 are always supported.
Exceptions
Type | Condition |
---|---|
ArgumentException |
-or-
|
PlatformNotSupportedException | If the platform doesn't support converting from bases other than 10 or 16. |
ToUInt32(String, Int32)
Converts the string representation of a number in a specified base to an equivalent 32-bit unsigned integer.
Declaration
[CLSCompliant(false)]
public static uint ToUInt32(string value, int fromBase = 10)
Parameters
Type | Name | Description |
---|---|---|
String | value | A string that contains the number to convert. |
Int32 | fromBase | The base of the number in |
Returns
Type | Description |
---|---|
UInt32 | A 32-bit unsigned integer that is equivalent to the number in |
Remarks
The .NET nanoFramework implementation of this method may provide only a subset of the equivalent .NET method.
Conversion will work with any base on most platforms. If a conversion is not supported, it will throw a PlatformNotSupportedException.
Note that base 10 and base 16 are always supported.
Exceptions
Type | Condition |
---|---|
ArgumentException |
-or-
|
PlatformNotSupportedException | If the platform doesn't support converting from bases other than 10 or 16. |
ToUInt64(String, Int32)
Converts the string representation of a number in a specified base to an equivalent 64-bit unsigned integer.
Declaration
[CLSCompliant(false)]
public static ulong ToUInt64(string value, int fromBase = 10)
Parameters
Type | Name | Description |
---|---|---|
String | value | A string that contains the number to convert. |
Int32 | fromBase | The base of the number in |
Returns
Type | Description |
---|---|
UInt64 | A 64-bit unsigned integer that is equivalent to the number in |
Remarks
The .NET nanoFramework implementation of this method may provide only a subset of the equivalent .NET method.
Conversion will work with any base on most platforms. If a conversion is not supported, it will throw a PlatformNotSupportedException.
Note that base 10 and base 16 are always supported.
Exceptions
Type | Condition |
---|---|
ArgumentException |
-or-
|
PlatformNotSupportedException | If the platform doesn't support converting from bases other than 10 or 16. |