0
Convert.ToString(icdoCalcWiz.ihstOldValues[enmCalcWiz.position_value.ToString()])!=icdoCalcWiz.position_value

Here LHS the value will come as ""(Empty)

But in RHS the value will be NULL

I have to satisfy the condition like if Empty or Null both are equal

But as per above condition both are not:

Domnic
  • 3,647
  • 9
  • 34
  • 60

4 Answers4

4

use this.

if (string.IsNullOrEmpty("any string"))
{
}

There is also a method String.IsNullOrWhitespace() which indicates whether a specified string is null, empty, or consists only of white-space characters.

if(String.IsNullOrWhitespace(val))
{
    return true;
}

The above is a shortcut for the following code:

if(String.IsNullOrEmpty(val) || val.Trim().Length == 0)
{
    return true;
}
Joel Peltonen
  • 12,301
  • 4
  • 63
  • 97
syed Ahsan Jaffri
  • 1,152
  • 2
  • 14
  • 33
1

You can try this....

static string NullToString( object Value )
{

    // Value.ToString() allows for Value being DBNull, but will also convert int, double, etc.
    return Value == null ? "" : Value.ToString();

    // If this is not what you want then this form may suit you better, handles 'Null' and DBNull otherwise tries a straight cast
    // which will throw if Value isn't actually a string object.
    //return Value == null || Value == DBNull.Value ? "" : (string)Value;
}

YOUR CODE Will Written as....

Convert.ToString(icdoCalcWiz.ihstOldValues[enmCalcWiz.position_value.ToString()])!=
NullToString(icdoCalcWiz.position_value)
Koen
  • 2,493
  • 1
  • 31
  • 43
Nick Vara
  • 63
  • 1
  • 1
  • 10
0

I think the following thread may help you regarding this

String Compare where null and empty are equal

Otherwise you can check null and assign empty string and compare

Community
  • 1
  • 1
Akhil
  • 1,750
  • 3
  • 28
  • 71
0

What about

string lhs = Convert.ToString(icdoCalcWiz.ihstOldValues[enmCalcWiz.position_value.ToString()]);
string rhs = icdoCalcWiz.position_value;

if ( (lhs == null || lhs == string.Empty) && (rhs == null || rhs == string.Empty)){
  return true;
} else {
  return lhs == rhs;
}
gturri
  • 12,179
  • 9
  • 39
  • 55