Getsuyodev, Programming is mainly used when constructing an application. Programming requires knowledge of application domains, algorithms, and programming language expertise. Programming can be developed in different logic based on developer knowledge.

How to validate a string in C#

TryParse is using to 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);

Comments are closed.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More