Convert.ToInt16 (String) converts string to 16-bit signed integer. : Convert to Int16 « Development « VB.Net






Convert.ToInt16 (String) converts string to 16-bit signed integer.

  

Imports System
Imports System.Globalization
Imports Microsoft.VisualBasic

Module ToInt16ProviderDemo
    Sub ConvertToInt16(ByVal numericStr As String, ByVal provider As IFormatProvider)
        Dim defaultValue As Object = Nothing

        Dim providerValue As Object = Nothing

        Try
            defaultValue = Convert.ToInt16(numericStr)
        Catch ex As Exception

        End Try

        Try
            providerValue = Convert.ToInt16(numericStr, provider)
        Catch ex As Exception

        End Try

        Console.WriteLine(defaultValue)
        Console.WriteLine(providerValue)
    End Sub

    Sub Main()
        Dim provider As NumberFormatInfo = New NumberFormatInfo()
        provider.NegativeSign = "neg "
        provider.PositiveSign = "pos "
        provider.NumberDecimalSeparator = "."
        provider.NumberGroupSeparator = ","
        provider.NumberGroupSizes = New Integer() {3}
        provider.NumberNegativePattern = 0

        ConvertToInt16("12345", provider)
    End Sub
End Module

   
    
  








Related examples in the same category

1.Convert.ToInt16 (Boolean) converts Boolean to 16-bit signed integer.
2.Convert.ToInt16 (Byte) converts 8-bit unsigned integer to 16-bit signed integer.
3.Convert.ToInt16 (Char) converts Unicode character to the equivalent 16-bit signed integer.
4.Convert.ToInt16 (Decimal) converts decimal number to 16-bit signed integer.
5.Convert.ToInt16 (Double) converts double-precision floating-point number to 16-bit signed integer.
6.Convert.ToInt16 (Int32) converts 32-bit signed integer to 16-bit signed integer.
7.Convert.ToInt16 Method (Int64) converts 64-bit signed integer to 16-bit signed integer.
8.Convert.ToInt16 (Object) converts object to a 16-bit signed integer.
9.Convert.ToInt16 (SByte) converts 8-bit signed integer to 16-bit signed integer.
10.Convert.ToInt16 (Single) converts single-precision floating-point number to 16-bit signed integer.
11.Convert.ToInt16 (String, Int32) converts string in a specified base to 16-bit signed integer.
12.Convert.ToInt16 (UInt16) converts 16-bit unsigned integer to 16-bit signed integer.
13.Convert.ToInt16 (UInt32) converts 32-bit unsigned integer to 16-bit signed integer.
14.Convert.ToInt16 (UInt64) converts 64-bit unsigned integer to 16-bit signed integer.