In the Java spec it's similar, never use == to compare strings, the
underlying objects will be compared for being the same object.
Sun Java VM happens to reuse string data (since strings are "immutable" [you
can't edit an existing string, but only make a new string or char array out
of it]), so that if you have two string fields holding the same text,
chances are they point to the same underlying "string" object. So sometimes
"==" will work in Sun Java VM, sometimes not (which can be quite tricky to
debug, but still saves some memory space esp. if you have quite big strings)
J# could do similarly, but still it doesn't solve your case, use ".equals"
method of a string class instance instead for comparison of two Java strings
(also the String class maybe has some static method to compare two given
strings)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
George Birbilis <birbilis@kagi.com>
Microsoft Most Valuable Professional
MVP J# for 2004, 2005
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ QuickTime (Delphi & ActiveX: VB, PowerPoint, .NET)
+ Plugs (InterProcess/Internet communication)
http://www.kagi.com/birbilis + Robotics
http://www.mech.upatras.gr/~robgroup
.........................................................................
[quoted text, click to view] > Use the CompareTo method on strings. Strings in J# are treated as true
> objects, so the equality operator will compile, but provide reference
> equality, not value equality.
> --
> David Anton
>
www.tangiblesoftwaresolutions.com > Instant C#: VB.NET to C# Converter
> Instant VB: C# to VB.NET Converter
> Instant J#: VB.NET to J# Converter
> Clear VB: Cleans up outdated VB.NET code
>
>
> "Al Christoph" wrote:
>
> > I am really puzzled in one piece of code the obvious worked and in
another it
> > didn't
> >
> > String s; // a global
> > ....
> > if (s == "") {
> > // blah blah blah
> > }
> > // the above works just fine
> > public void ...
> > String s; // local
> > if (s == "") {
> > // blah blah blah
> > }
> > // blah blah blah never happends even when quick watch shows the
expression
> > is true.
> >
> > I finally resorted to s.get_Length == 0 as the expression and it works
fine.
> >
> > What gives????
> >
> > Side bar to MS lurkers. I'm appalled at the quality of the VS 2003
internal
> > doco for J#. Look up boolean expression in the index and all you get is
> > Crystal Repots. UGH!!!!! BTW one of my mottos is that "If Bill Gates had
a
> > hand in it, you shouldn't need a manual." (The other is "Bill Gates
won.")
> > --
> > Regards,
> > Al Christoph
> > Senior Consultant and Proprietor
> > Three Bears Software, LLC
> > just right software @ just right prices @3bears.biz