System.Convert.ToInt16 C# (CSharp) Method

ToInt16() public static method

public static ToInt16 ( String value, int fromBase ) : short
value String
fromBase int
return short
        public static short ToInt16 (String value, int fromBase) {
            if (fromBase!=2 && fromBase!=8 && fromBase!=10 && fromBase!=16) {
                throw new ArgumentException(Environment.GetResourceString("Arg_InvalidBase"));
            }
            int r = ParseNumbers.StringToInt(value,fromBase,ParseNumbers.IsTight | ParseNumbers.TreatAsI2);
            if (fromBase != 10 && r <= UInt16.MaxValue)
                return (short)r;

            if (r < Int16.MinValue || r > Int16.MaxValue)
                throw new OverflowException(Environment.GetResourceString("Overflow_Int16"));
            return (short) r;
        }

Same methods

Convert::ToInt16 ( DateTime value ) : short
Convert::ToInt16 ( String value ) : short
Convert::ToInt16 ( String value, IFormatProvider provider ) : short
Convert::ToInt16 ( bool value ) : short
Convert::ToInt16 ( byte value ) : short
Convert::ToInt16 ( char value ) : short
Convert::ToInt16 ( decimal value ) : short
Convert::ToInt16 ( double value ) : short
Convert::ToInt16 ( float value ) : short
Convert::ToInt16 ( int value ) : short
Convert::ToInt16 ( long value ) : short
Convert::ToInt16 ( object value ) : short
Convert::ToInt16 ( object value, IFormatProvider provider ) : short
Convert::ToInt16 ( sbyte value ) : short
Convert::ToInt16 ( short value ) : short
Convert::ToInt16 ( uint value ) : short
Convert::ToInt16 ( ulong value ) : short
Convert::ToInt16 ( ushort value ) : short

Usage Example

Beispiel #1
0
 private static void RegisterUInt64Conversions(
     ITypeConverterRegistry registry)
 {
     registry.Register <ulong, byte>(from => SysConv.ToByte(from));
     registry.Register <ulong, short>(from => SysConv.ToInt16(from));
     registry.Register <ulong, int>(from => SysConv.ToInt32(from));
     registry.Register <ulong, long>(from => SysConv.ToInt64(from));
     registry.Register <ulong, ushort>(from => SysConv.ToUInt16(from));
     registry.Register <ulong, uint>(from => SysConv.ToUInt32(from));
     registry.Register <ulong, decimal>(from => SysConv.ToDecimal(from));
     registry.Register <ulong, float>(from => SysConv.ToSingle(from));
     registry.Register <ulong, double>(from => SysConv.ToDouble(from));
     registry.Register <ulong, string>(from =>
                                       from.ToString(CultureInfo.InvariantCulture));
 }
All Usage Examples Of System.Convert::ToInt16