What's the use of System.String.Copy in .NET?

前端 未结 8 980
误落风尘
误落风尘 2020-12-13 07:58

I\'m afraid that this is a very silly question, but I must be missing something.

Why might one want to use String.Copy(string)?

The documentation says the me

8条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-13 08:32

    With String.Copy you are actually allocating new memory and copying the characters from one string to another; you get a completely new instance as opposed to having both variables being the same instance. This may matter if you use the string with unmanaged code which deals with the memory locations directly and can mutate the string.

提交回复
热议问题