To check if a string is a number in C# and VB.NET you can use the following snippet.

Sample C#

public static bool IsNumeric(String input)
{
	double checkNumber;
	return double.TryParse(input, out checkNumber);
}

Sample VB.NET

Public Shared Function IsNumeric(input As [String]) As Boolean
	Dim checkNumber As Double
	Return Double.TryParse(input, checkNumber)
End Function

One thought on “How to check if a string is a number in C# and VB.NET”

Leave a Reply