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 @   yinghualeihenmei  阅读(125)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· Obsidian + DeepSeek:免费 AI 助力你的知识管理,让你的笔记飞起来!
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
点击右上角即可分享
微信分享提示