Net-informations.com
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)

Parameters:

param: The parameter string.

result: The result will store in this variable

Returns:

returns True or False




using System;
using System.Windows.Forms;

namespace WindowsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        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);
        }
    }
}

 CSharp String - Related Contents


 CSharp String - Related Programs