a very strange problem

  • Thread starter Thread starter Wajih-ur-Rehman
  • Start date Start date
W

Wajih-ur-Rehman

string val = reader.ReadElementString(localName); //reader is XmlTextReader

if ( val != null )

{

if (val.Length != 0)

{

}

}

If the value of val comes out to be an empty string, it still goes in both
of the if conditions :| :| :| :| ( I have even tried val.Trim().Length != 0
as well.....it doesnt work too)

I have checked in the Watch Window that the length of val *is* 0 and also
the expression val.Lenght != 0 *is* evaluated to false, but still the
control gets into the if condition

Anyone has *any* explanation for this????????

Regards
 
Wajih-ur-Rehman said:
string val = reader.ReadElementString(localName); //reader is XmlTextReader

if ( val != null )

{

if (val.Length != 0)

{

}

}

If the value of val comes out to be an empty string, it still goes in both
of the if conditions :| :| :| :| ( I have even tried val.Trim().Length != 0
as well.....it doesnt work too)

I have checked in the Watch Window that the length of val *is* 0 and also
the expression val.Lenght != 0 *is* evaluated to false, but still the
control gets into the if condition

Anyone has *any* explanation for this????????

Only that it's almost certainly a bug in the debugger. Note that in
VS.NET 2002 the watch window's detection of string lengths was
incorrect - it had problems with embedded nulls.

I suspect you'll find that running the code when you're not stepping
through it won't show the problem.
 
Thank you Jon for your comments. Actually i already have tried it without
debugging and still the problem occurs. Any other suggestion or comment?
 
Wajih-ur-Rehman said:
Thank you Jon for your comments. Actually i already have tried it without
debugging and still the problem occurs. Any other suggestion or comment?

If it occurs when you're not debugging, I suspect you *have* actually
got some data. Could you post a short but complete example which
demonstrates the problem?

See http://www.pobox.com/~skeet/csharp/complete.html for what I mean by
that.
 
Back
Top