Converts the string representation of a number to its 32-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 32-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  w w  .  j  a  v  a  2s  .  com*/

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

Related Tutorials