String comparison performance in C#

后端 未结 10 1650
一向
一向 2020-12-20 11:42

There are a number of ways to compare strings. Are there performance gains by doing one way over another?

I\'ve always opted to compare strings like so:



        
10条回答
  •  误落风尘
    2020-12-20 12:03

    If the equality operator actually performed worse than CompareTo - wouldn't Microsoft make the implementation of the equality operator call CompareTo?

    Just use the equality operator to test for equality.

提交回复
热议问题