Progress Monitor for IdealProgrammer.com
Take Swift, Intelligent, Massive, Planned, Loving, Effective (S.I.M.P.L.E.) Action to Transform Self into Ideal
Skip Repetitive Navigational Links
Home
News
Presenters
Register
Contact
Categories
Titles
Converter
Code Samples
C# ASP.NET
C# Console
HTML
JavaScript
SQL Server
VB ASP.NET
VB Console
Please login
C-Sharp IsNumeric Example Syntax - C# IsNumeric - Sample Code
Description:
Illustrates the C# Syntax for IsNumeric.
Example Class Main:
using System; public class clsIsNumeric { public void Main() { //**************************************************************************************** // Example #1: IsNumeric(string) //**************************************************************************************** //**************************************************************************************** // Example #1: IsNumeric(string) // Not supported in C#, but here is code that duplicates what happens in VB // Returns a Boolean value that indicates if the string is Numeric. //**************************************************************************************** Console.WriteLine("Example #1: IsNumeric(strField)"); string strField = "100.00"; Console.WriteLine(SimulateIsNumeric.IsNumeric(strField)); //Returns True - decimals are numeric //write blank line to make output easier to read Console.WriteLine(); //Prevent console from closing before you press enter Console.ReadLine(); } } //---------------------------------------------------------------------------------------- // Copyright © 2003 - 2011 Tangible Software Solutions Inc. // This class can be used by anyone provided that the copyright notice remains intact. // // This class simulates the behavior of the classic VB 'IsNumeric' function. //---------------------------------------------------------------------------------------- public static class SimulateIsNumeric { public static bool IsNumeric(object expression) { if (expression == null) return false; double testDouble; if (double.TryParse(expression.ToString(), out testDouble)) return true; //VB's 'IsNumeric' returns true for any boolean value: bool testBool; if (bool.TryParse(expression.ToString(), out testBool)) return true; return false; } }
Example Class Program:
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace CSharp_Syntax { class Program { static void Main(string[] args) { clsIsNumeric myIsNumeric = new clsIsNumeric(); myIsNumeric.Main(); } } }
Home
News
Presenters
Register
Contact
Categories
Titles
Converter
Code Samples
C# ASP.NET
C# Console
HTML
JavaScript
SQL Server
VB ASP.NET
VB Console