Why avoid string.ToLower() when doing case-insensitive string comparisons?

后端 未结 5 1126
温柔的废话
温柔的废话 2021-01-19 05:38

I have read that when in your application you do a lot of string comparison and using ToLower method, this method is quite costly. I was wondering of anyone could explain to

5条回答
  •  不思量自难忘°
    2021-01-19 05:47

    Each time you call ToLower(), a new copy of the string will be created (as opposed to making the case changes in-place). This can be costly if you have many strings or long strings.

    From String.ToLower docs:

    Returns a copy of this string converted to lowercase.

提交回复
热议问题