Converts the string representation of a number to its 16-bit signed integer equivalent. If the conversion failed the return value is 0. - CSharp System

CSharp examples for System:String Convert

Description

Converts the string representation of a number to its 16-bit signed integer equivalent. If the conversion failed the return value is 0.

Demo Code


using System.Text.RegularExpressions;
using System.Text;
using System.Security.Cryptography;
using System.Linq;
using System.Globalization;
using System.Collections.Generic;
using System;//from  w  ww . j  a va  2s  .c om

public class Main{
        /// <summary>
        /// Converts the string representation of a number to its 16-bit signed integer
        /// equivalent. If the conversion failed the return value is 0.
        /// </summary>
        /// <returns>System.Int16</returns>
        public static short ToShort(this string input)
        {
            short shortValue;
            short.TryParse(input, out shortValue);
            return shortValue;
        }
}

Related Tutorials