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,817
  • 9
  • 40
  • 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
  • 13,025
  • 6
  • 64
  • 100
syed Ahsan Jaffri
  • 1,160
  • 2
  • 14
  • 34
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,501
  • 1
  • 32
  • 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,918
  • 5
  • 30
  • 74
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
  • 13,807
  • 9
  • 40
  • 57