Difference between the different overloads of String.Compare

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-23 09:26:45

问题


Concretely what is the difference between

  • String.Compare(String, String, StringComparison) and
  • String.Compare(String, String, CultureInfo, CompareOptions)

I feel like that the second one offers more options (comparison using any culture instead of only the current one or invariant one, ignore special characters, ignore the width of katakanas (!!) etc...) than the first one. Both have been introduced it in .NET 2.0 so I guess it can't be a question of backward compatibility.

So what's the difference and when should I use the first one and when should I use the second one?

I had a look at this post and this article, but I think they're dealing with a slightly different matters.


回答1:


Your answer is in the remarks for the second overload.

http://msdn.microsoft.com/en-us/library/cc190529.aspx

"The comparison uses the culture parameter to obtain culture-specific information, such as casing rules and the alphabetical order of individual characters. For example, a particular culture could specify that certain combinations of characters be treated as a single character, that uppercase and lowercase characters be compared in a particular way, or that the sort order of a character depends on the characters that precede or follow it."

The other overload just uses the default culture.



来源:https://stackoverflow.com/questions/10652851/difference-between-the-different-overloads-of-string-compare

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!