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.


  1. param: The parameter string.
  2. result: The result will store in this variable.


  1. 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) 2019    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.
SiteMap  | Terms  | About