Skip to content

Need to doc that String.Copy is obsolete as of .NET Core 3 #2382

@GrabYourPitchforks

Description

@GrabYourPitchforks

Context: https://github.com/dotnet/corefx/issues/33602 and https://github.com/dotnet/corefx/blob/467d45e3950e8daeda9373396da8061f5b8b3787/src/System.Runtime/ref/System.Runtime.cs#L2330-L2331

We obsoleted (as warning) the String.Copy method in .NET Core 3 and created the fwlink https://go.microsoft.com/fwlink/?linkid=2084035 for inclusion in the obsolete message. Current the fwlink points back to the original GitHub issue, but we should update the String.Copy docs to mention alternatives and redirect the fwlink to the official documentation.

Ideally we'd want to say something like the below, with examples of proper usage.

  • You probably didn't ever need to call this method at all, and you can just use the original string instance since string instances are immutable.

  • If you need to create a mutable buffer with the same contents as the original string, use string.ToCharArray() or the StringBuilder(string) ctor.

  • If you need to create a mutable copy of the string for interop purposes, use the method Marshal.StringToHGlobalUni(string). Remember to free the unmanaged memory when you're done.

There may be other scenarios but I can't think of them offhand.

Metadata

Metadata

Assignees

Labels

🏁 Release: .NET Core 3.0:checkered_flag: Release: .NET Core 3.0Pri1Indicates issues/PRs that are high priority

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions