Willem Odendaal

the coder's point of view

<October 2008>
SuMoTuWeThFrSa
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678


Navigation

I Read

Subscriptions

Post Categories



String Comparisons

In Java you were not allowed to compare strings using the == operator (the == operator would do a reference comparison). So you had to use the Equals() method instead. For example...

if (userName.Equals(”Willem”)) { ... }

Instead of...

if (userName == “Willem“) {...}

That stuck with me. Now, in C#, I always compare strings using the Equals() method. However, according to this acticle, System.String overloads the == operator and calls Equals() internally. Good to have that one cleared up.

On the rare occasion that you really do want to do a reference comparison, I guess you would have to use Object.ReferenceEquals.

posted on Tuesday, April 12, 2005 5:43 AM by willemo





Powered by Dot Net Junkies, by Telligent Systems