我如何在null ==""之间停止比较? ? [英] How can i stop comparasion between null=="" ?
问题描述
我正在做的是
if(emp.name!= this.name)
{
//我将它添加到审计跟踪。
}
但有时如果emp.name = null和this.name =if语句在condign为true时执行,并且在我的审计网格中旧值=空白且新值=空白快速得到...我不喜欢我想要
我怎么能让这个条件堕落
< blockquote>将条件更改为
if(!String.IsNullOrEmpty(emp.name)&&(emp.name!= this.name))
if (!string.IsNullOrEmpty(emp.name)&&!string.IsNullOrEmpty( this .name)&&(emp.name!= this .name)){
// 无论
}
特定案例的解决方案,当其中一个条款为空而另一个为空时
if (!((emp.name == null && this .name == String .Empty)|| (emp.name == String .Empty&& this .name == null ))&& (emp.name!= this .name)){
// 无论
}
应该有办法简化这些条件,但我现在没有时间。
[/ EDIT]
我认为你的问题的最佳方法是convert.tostring ()
据我所知它处理空值
所以你的新比较将是
if (convert.tostring( emp.name)!= convert.tostring( this .name))
{
// 我将其添加到审计跟踪中。
}
问候......:)
what i am doing is
if(emp.name!=this.name)
{
//I am adding it to audit trail .
}
but sometimes if emp.name=null and this.name="" the if statement gets executed as the condign is true and in my audit grid old value= blank and new value = blank gets speedily ... which i don't want to
how can i this condion makes fall
Change the condition to
if(!String.IsNullOrEmpty(emp.name) && (emp.name!=this.name))
if (!string.IsNullOrEmpty(emp.name) && !string.IsNullOrEmpty(this.name) && (emp.name != this.name)) { // Whatever }
[EDIT] Solution for specific case when one of the terms is null and the other is empty
if (!((emp.name == null && this.name == String.Empty) || (emp.name == String.Empty && this.name == null)) && (emp.name != this.name)) { // Whatever }
There should be a way to simplify these conditions but I do not have time for that now.
[/EDIT]
I think best approach to your problem is convert.tostring()
as per my knowledge it handles null values
so your new comparison would be
if(convert.tostring(emp.name)!=convert.tostring(this.name)) { //I am adding it to audit trail . }
regards...:)
这篇关于我如何在null ==""之间停止比较? ?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!