Convert String to Int Value Or Default - CSharp System

CSharp examples for System:Int32

Description

Convert String to Int Value Or Default

Demo Code


using System.Text;
using System.IO;//from w  w w  .  j  a  va  2 s. co m
using System.Globalization;
using System.Collections.Generic;
using System;

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

Related Tutorials