C# 判断数字是否为空

来源:百度知道 编辑:UC知道 时间:2024/05/20 16:49:16
怎么判断?
int id = int.Parse(GridView1.Rows[e.RowIndex].Cells[0].Text);
我就想知道它是不是空的

int id = 0
try{
id = int.Parse(GridView1.Rows[e.RowIndex].Cells[0].Text);
}catch{}

if (id<1){
// GridView1.Rows[e.RowIndex].Cells[0].Text is empty Or GridView1.Rows[e.RowIndex].Cells[0] is null
}

或者

int id = 0;
String str = GridView1.Rows[e.RowIndex].Cells[0].Text;

str=System.Text.RegularExpressions.Regex.Replace(str,@"(\s+)?","");

if (str!=""){
id = int.Parse(str);
}

就你的代码来说

if (GridView1.Rows[e.RowIndex].Cells[0] == null)
MessageBox.Show("空")

如果是空的话就会有问题了啊