int Value = 0;
    bool ValueIsNumeric = int.TryParse(MyStringValue, out Value);

For larger values:


	UInt64 i = 0;
    ValueIsNumeric = UInt64.TryParse(MyStringValue, out Value);

Verifying a form TextBox value example


    //*****************************************************
    //*****************************************************
    //*********** VERIFY NUMBERIC TEXT BOX VALUE **********
    //*****************************************************
    //*****************************************************
    private void VerifyTextBoxNumericValue(ref TextBox TextBox1, int MinValue, int MaxValue, int DefaultValue)
    {
        try
        {
            int Value = 0;
            if (!(int.TryParse(TextBox1.Text, out Value)))
            {
                TextBox1.Text = Convert.ToString(DefaultValue);
            }

            if (Value < MinValue)
                TextBox1.Text = Convert.ToString(MinValue);
            if (Value > MaxValue)
                TextBox1.Text = Convert.ToString(MaxValue);
        }
        catch (Exception)
        {
        }
    }

    VerifyTextBoxNumericValue(ref MyTextBox, 0, 256, 256);

 

USEFUL?
We benefit hugely from resources on the web so we decided we should try and give back some of our knowledge and resources to the community by opening up many of our company’s internal notes and libraries through mini sites like this. We hope you find the site helpful.
Please feel free to comment if you can add help to this page or point out issues and solutions you have found, but please note that we do not provide support on this site. If you need help with a problem please use one of the many online forums.