C#?ж???????????????????
???????????? ???????[ 2012/12/3 10:07:13 ] ????????
?????????C#???????е????????????ж????????????????????????????????????????????????????
?????????????????? try{} catch{} ???
?????????????try???????????string??????????????????int???????????????????????????????????????????catch?????????????????????????????????????????
???????????????????????string????????int?????
??????1??int.Parse(string);
??????2??Convert.ToInt16(string); //?????????????λ??????4??????????Convert.ToInt32()
??????3??Convert.ToInt32(string);
???????????????TextBox1??????????Button1??????????????ж???????е????????????????????????????????????????
protected void Button1_Click(object sender?? EventArgs e)
{
string message = TextBox1.Text.Trim();
int result;
if(isNumberic(message??out result))
{
string tt="<script>alert('??????????????????"+result+"')</script>";
Page.ClientScript.RegisterStartupScript(this.GetType()?? ""?? tt);
}
else
Page.ClientScript.RegisterStartupScript(this.GetType()?? ""?? "<script>alert('???????')</script>");
}
protected bool isNumberic(string message??out int result)
{
//?ж??????????????
//????????????????????????out???????????????true?? ?????false
result = -1; //result ?????out ????????
try
{
//????????????????????4???????????????????????????
//???λ??????4??????????Convert.ToInt32() ??int.Parse()
//result = int.Parse(message);
//result = Convert.ToInt16(message);
result = Convert.ToInt32(message);
return true;
}
catch
{
return false;
}
}
?????????????????int???double???? double.Parse()???????????ж??????????????????
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11