vb.net 有IsNumeric方法,很方便。
c#可以用这个:
try
{
int x = Int32.Parse(textBox1.Text);
//errorProvider1.SetError(textBox1, "");
}
catch (Exception e)
{
//errorProvider1.SetError(textBox1, "Not an integer value.");
}
c#可以用这个:
try
{
int x = Int32.Parse(textBox1.Text);
//errorProvider1.SetError(textBox1, "");
}
catch (Exception e)
{
//errorProvider1.SetError(textBox1, "Not an integer value.");
}
解决方案 »
- 导出一个时间段统计表
- Visual Studio 2005 代码段
- 关于类之间交叉引用的问题,如何保证对象的正确释放?
- Datagridview的超级简单问题
- 阅读器关闭时 FieldCount 的尝试无效,新手请教各位。
- Winform中怎样捕捉datagrid的表头单击排序事件??????
- 请大家帮忙,如何在程序中提交一个 form
- Webserive的参数传递问题
- datagridview自动编号
- 在VS.Net中如何使注释生成已编译的HTML帮助文件?
- 对.net很熟,想转j2ee,需要多长的时间,困难吗?(在广西,精通.net而找不到高薪的工作,无奈!—)
- 关于用CDO发邮件的程序(不要看那么多代码,其实很简单)。
char temp;
int L, D, O; //字母,数字,其它Console.WriteLine("input a string:");
sur = Console.ReadLine();for (int i = 0, i < sur.Length, i++)
{
temp = sur[i];
if (char.IsLetterOrDigit(temp)) //是字母或数字
{
if (char.IsLetter(temp) //是字母
{
L++; //字母加一
}
else
{
D++; //数字加一
}
else
{
O++; //其它
}
}还有一些别的方法,例如:IsDigit……
---------------------
同意,C#也可以使用IsNumeric方法,添加引用->Microsoft Visual Basic.Net
RunTime ,然后用Microsoft.VisualBasic.Information.IsNumeric()判断是否是数字。如果用捕获异常的方法:
private bool isDNumeric(string mInput)
{
try
{
decimal cmicDml=decimal.Parse(mInput);
return true;
}
catch (Exception ex)
{
string cmicErr=ex.Message;
return false;
}
}
{
int i=int.Parase("123");
}
catch
{
MessageBox.show("error");
}