C# 怎么把空值转换为0

原文链接:https://www.zzzyk.com/show/21a0aaa76b88192e.htm

空值直接转换为int会报错,所以需要转换下,原文看起来比较乱,在此整理下:

第一种:

if((string.isnullorempty(this.textbox1.value))
{
      this.textbox1.value="0";

第二种:

int n = 0;
int.TryParse(this.textBox.Text, out n);

第三种:

this.textBox1.Text = this.textBox1.Text == null ? "0" : this.textBox1.Text;

第四种:

 if(this.textbox1.value!=string.Empty)

{

   this.textbox1.value="0";

}

第五种:

this.txtValue.Text = string.IsNullOrEmpty(this.txtValue.Text) ? "0" : this.txtValue.Text;

第六种:

 If row(jIs DBNull.Value Then
                row(j0
            End If
            If row(j).ToString.Length 0 Then
                row(j0
            End If

posted @ 2023-07-09 22:23  yinghualeihenmei  阅读(95)  评论(0编辑  收藏  举报