Convert String to Int Value Or Zero - CSharp System

CSharp examples for System:Int32

Description

Convert String to Int Value Or Zero

Demo Code


using System.Text;
using System.IO;/*w  ww . j a  v a  2  s  .c o m*/
using System.Globalization;
using System.Collections.Generic;
using System;

public class Main{
        public static int IntValueOrZero(this string value)
        {
            int result;
            if (int.TryParse(value, out result))
            {
                return result;
            }
            else
            {
                return 0;
            }
        }
}

Related Tutorials