开发者

String comparison : operator==() vs. Equals() [duplicate]

This question开发者_如何学运维 already has answers here: Closed 12 years ago.

Possible Duplicate:

C#: Are string.Equals() and == operator really same?

For string comparison, which approach is better (and safe):

string s1="Sarfaraz";
string s2="Nawaz";

bool result1 = (s1==s2) ;//approach 1
bool result2 = s1.Equals(s2) ;//approach 2

Or both are same under the hood?


I like Equals() because the available StringComparison option is very useful.

The == and != operators are based on the value, so they are safe to use, even though String is a reference type.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜