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.

Parameters:

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

Returns:

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





net-informations.com (C) 2019    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.