Determines whether the specified text is numeric. I a string is numeric if it contains only numbers. This routine does not check for commas, decimal points etc. - CSharp System

CSharp examples for System:String Contain

Description

Determines whether the specified text is numeric. I a string is numeric if it contains only numbers. This routine does not check for commas, decimal points etc.

Demo Code


using System.Linq;
using System.Diagnostics.Contracts;
using System;//  w  w  w . j  a  v a  2s.  co m

public class Main{
        /// <summary>
        /// Determines whether the specified text is numeric.  I a string is numeric if it contains
        /// only numbers.  This routine does not check for commas, decimal points etc.
        /// </summary>
        /// <param name="text">The text.</param>
        /// <returns>
        ///   <c>true</c> if the specified text is numeric; otherwise, <c>false</c>.
        /// </returns>
        public static bool IsNumeric(this string text)
        {
            return text.Cast<char>().All(char.IsNumber);
        }
}

Related Tutorials