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

后端 未结 5 1127
温柔的废话
温柔的废话 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:57

    As somebody already answered, ToLower() will create a new string object, which is extra cost comparing to using "IgonoreCase". If this ToLower is triggered frequently, you end up creating a lot of small objects in your heap, and will add Garbage Collection time, which becomes a performance penalty.

提交回复
热议问题