SiteMap  | About    

How to validate a string in C#

TryParse is using for determine whether a string is a valid representation of a specified numeric type or not. TryParse method that is implemented by all primitive numeric types and also by types such as DateTime and IPAddress.

bool int.TryParse(string param , out int result)


param: The parameter string.

result: The result will store in this variable


returns True or False

using System;
using System.Windows.Forms;

namespace WindowsApplication1
    public partial class Form1 : Form
        public Form1()

        private void button1_Click(object sender, EventArgs e)
            bool isNumeric;
            int i;
            string str = "100";
            isNumeric = int.TryParse(str, out i);
            MessageBox.Show("The value of i is " + i);
} (C) 2015    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.