In some languages (e.g. C++) you can't use operators like == for string comparisons as that would compare the address of the string object, and not the string itself. However, in C# you can use == to compare strings, and it will actually compare the content of the strings. But there are also string functions to handle such comparisons, so my question is; should you?
Given two strings:
string aa = "aa";
string bb = "bb";
Should you compare them like this:
bool areEqual = (aa == bb);
Or should you use the Equal function, like this:
bool areEqual = aa.Equals(bb);
Is there any technical difference anyway? Or reasonable arguments for best practice?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…