Convert.ToString Method (UInt16)

May 11, 2014

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

This API is not CLS-compliant. 

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)

'Declaration
<CLSCompliantAttribute(False)> _
Public Shared Function ToString ( _
	value As UShort _
) As String

Parameters

value
Type: System.UInt16
A 16-bit unsigned integer.

Return Value

Type: System.String
The String equivalent of the value of value.

This implementation is identical to UInt16.ToString.

The following code example converts an unsigned 16-bit integer to a String with the ToString method, using default formatting.


' Example of the Convert.ToString( numeric types ) and 
' Convert.ToString( numeric types, IFormatProvider ) methods.
Imports System.Globalization

Module Example

   Public Sub Demo(ByVal outputBlock As System.Windows.Controls.TextBlock)

      ' Create a NumberFormatInfo object and set several of its
      ' properties that apply to numbers.
      Dim provider As NumberFormatInfo = New NumberFormatInfo()
      Dim formatter As String = "{0,22}   {1}"

      ' These properties will affect the conversion.
      provider.NegativeSign = "minus "
      provider.NumberDecimalSeparator = " point "

      ' These properties will not be applied.
      provider.NumberDecimalDigits = 2
      provider.NumberGroupSeparator = "."
      provider.NumberGroupSizes = New Integer() {3}

      ' Convert these values using default values and the
      ' format provider created above.
      Dim ByteA As Byte = 140
      Dim SByteA As SByte = Convert.ToSByte(-60)
      Dim UInt16A As UInt16 = Convert.ToUInt16(61680)
      Dim Int16A As Short = -3855

      Dim UInt32A As UInt32 = Convert.ToUInt32(4042322160)
      Dim Int32A As Integer = -252645135
      Dim UInt64A As UInt64 = _
                          Convert.ToUInt64(8138269444283625712)
      Dim Int64A As Long = -1085102592571150095

      Dim SingleA As Single = -32.375F
      Dim DoubleA As Double = 61680.3855
      Dim DecimA As Decimal = 4042322160.252645135D
      Dim ObjDouble As Object = CType(-98765.4321, Object)

      outputBlock.Text &= "This example of " & _
          "Convert.ToString( numeric types ) and " & vbCrLf & _
          "Convert.ToString( numeric types, IFormatProvider ) " & _
          vbCrLf & "converts values of each of the CLR base " & _
          "numeric types to strings, " & vbCrLf & "using " & _
          "default formatting and a NumberFormatInfo object." & vbCrLf
      outputBlock.Text &= vbCrLf & _
          "Note: Of the several NumberFormatInfo properties " & _
          "that are changed, " & vbCrLf & "only the negative " & _
          "sign and decimal separator affect the conversions." & vbCrLf
      outputBlock.Text &= String.Format(vbCrLf & formatter, _
          "Default", "Format Provider") & vbCrLf
      outputBlock.Text &= String.Format(formatter, _
          "-------", "---------------") & vbCrLf

      ' Convert the values with and without a format provider.
      outputBlock.Text &= String.Format(formatter, Convert.ToString(ByteA) & vbCrLf, _
          Convert.ToString(ByteA, provider))
      outputBlock.Text &= String.Format(formatter, Convert.ToString(SByteA) & vbCrLf, _
          Convert.ToString(SByteA, provider))
      outputBlock.Text &= String.Format(formatter, Convert.ToString(UInt16A) & vbCrLf, _
          Convert.ToString(UInt16A, provider))
      outputBlock.Text &= String.Format(formatter, Convert.ToString(Int16A) & vbCrLf, _
          Convert.ToString(Int16A, provider))

      outputBlock.Text &= String.Format(formatter, Convert.ToString(UInt32A) & vbCrLf, _
          Convert.ToString(UInt32A, provider))
      outputBlock.Text &= String.Format(formatter, Convert.ToString(Int32A) & vbCrLf, _
          Convert.ToString(Int32A, provider))
      outputBlock.Text &= String.Format(formatter, Convert.ToString(UInt64A) & vbCrLf, _
          Convert.ToString(UInt64A, provider))
      outputBlock.Text &= String.Format(formatter, Convert.ToString(Int64A) & vbCrLf, _
          Convert.ToString(Int64A, provider))

      outputBlock.Text &= String.Format(formatter, Convert.ToString(SingleA) & vbCrLf, _
          Convert.ToString(SingleA, provider))
      outputBlock.Text &= String.Format(formatter, Convert.ToString(DoubleA) & vbCrLf, _
          Convert.ToString(DoubleA, provider))
      outputBlock.Text &= String.Format(formatter, Convert.ToString(DecimA) & vbCrLf, _
          Convert.ToString(DecimA, provider))
      outputBlock.Text &= String.Format(formatter, Convert.ToString(ObjDouble) & vbCrLf, _
          Convert.ToString(ObjDouble, provider))
   End Sub
End Module

' This example of Convert.ToString( numeric types ) and
' Convert.ToString( numeric types, IFormatProvider )
' converts values of each of the CLR base numeric types to strings,
' using default formatting and a NumberFormatInfo object.
' 
' Note: Of the several NumberFormatInfo properties that are changed,
' only the negative sign and decimal separator affect the conversions.
' 
'                Default   Format Provider
'                -------   ---------------
'                    140   140
'                    -60   minus 60
'                  61680   61680
'                  -3855   minus 3855
'             4042322160   4042322160
'             -252645135   minus 252645135
'    8138269444283625712   8138269444283625712
'   -1085102592571150095   minus 1085102592571150095
'                -32.375   minus 32 point 375
'             61680.3855   61680 point 3855
'   4042322160.252645135   4042322160 point 252645135
'            -98765.4321   minus 98765 point 4321


Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

Show:
© 2014 Microsoft