不对啊: if (int.Parse(textBox1.Text)) { label1.Text="1"; } else { label1.Text="2"; } D:\VS程序\testC\Form2.cs(116): Cannot implicitly convert type 'int' to 'bool'
or 正则表达式 using System.Text.RegularExpressions; ......string str;......bool yn=Regex.IsMatch(str,@"^[0-9]+$"); if(yn==true) { MessageBox.Show("y"); //数字 } else { MessageBox.Show("n"); //不是数字}
{
int.Parse(text1.Text);
}
catch
{
MessageBox.Show("不是");
}
if (int.Parse(textBox1.Text))
{
label1.Text="1"; }
else
{
label1.Text="2";
}
D:\VS程序\testC\Form2.cs(116): Cannot implicitly convert type 'int' to 'bool'
正则表达式
using System.Text.RegularExpressions; ......string str;......bool yn=Regex.IsMatch(str,@"^[0-9]+$");
if(yn==true)
{ MessageBox.Show("y"); //数字
}
else
{
MessageBox.Show("n"); //不是数字}
if(System.Text.RegularExpressions.Regex.IsMatch(this.TextBox1.Text,@"^[+|-]?\d+\.?\d*$"))
{
...
}
else
{
...
}
{
try
{
Convert.ToDouble(number);
return true;
}
catch
{
return false;
}
}///////////////
if (CovertDouble(textBox1.Text) == false)
{
//错误处理
}
*检查一个字符串是否全是数字
*@param string v 要检查的字符串
*return boolean
*/
function IsNumber( v )
{
var valideString = "0123456789";
var vArray = v.split(""); for( i = 0; i < vArray.length; i ++ ){
if( valideString.indexOf( vArray[i] ) < 0 ){
return false;
}
}
return true;
}