请说明如何使用tryparse进行验证 [英] Please explaion how the tryparse is used for validation

查看:109
本文介绍了请说明如何使用tryparse进行验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

private void button1_Click(object sender, EventArgs e)
{
    int number2;
    if (int.TryParse(textBox1.Text, out number2))
    {
        textBox2.Text = ("tryparse method succeed");
    }
    else { textBox2.Text=("value entered is not numeric"); }
}

推荐答案

此int.tryparse方法将采用字符串并将其尝试转换为整数.如果它不能转换,那么它将返回false.如果成功,它将返回true,并且还将返回in参数,它将保存转换后的整数值.
This int.tryparse method will take the string and try to convert it to integer. If it is not able to convert, then it will return false. If it is success, it will return true and also in out parameter, it will save the converted integer value.


这篇关于请说明如何使用tryparse进行验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆