Convert String To Int - CSharp System

CSharp examples for System:Converter

Description

Convert String To Int

Demo Code


using System.Threading.Tasks;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System;/*w w w  .  j  a  v  a 2 s.c o m*/

public class Main{
        public static int ConvertStringToInt(string value)
        {
            int intValue;

            bool IsValid = int.TryParse(value, out intValue);
            if (IsValid == false)
            {
                throw new Exception("String is not in the right format - Int32");
            }
            return intValue;
        }
}

Related Tutorials