Convert String to Decimal Value Or Null - CSharp System

CSharp examples for System:Decimal

Description

Convert String to Decimal Value Or Null

Demo Code


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

public class Main{
        public static decimal? DecimalValueOrNull(this string value)
        {
            decimal result;
            if (decimal.TryParse(value, out result))
            {
                return result;
            }
            else
            {
                return null;
            }

        }
}

Related Tutorials