dotnet / dotnet/dotnet-api-docs
String.PadLeft doesn't allocate on net core in some cases
Open
area-System.Runtime
Pri3
untriaged
- Dominant language
- C#
- Stars
- 949
- Forks
- 1.7k
- Avg merge
- 3d 27m
- Merged PRs (30d)
- 49
Description
https://github.com/dotnet/dotnet-api-docs/blob/main/xml/System/String.xml
> If `totalWidth` is equal to the length of this instance, the method returns _**`a new string`**_ that is identical to this instance.
This sentence is no longer true for NET Core (true for NET Framework). Both overloads.
```c#
object.ReferenceEquals("aa".PadLeft(2), "aa") == true;
```
https://sharplab.io/#v2:C4LgTgrgdgNAJiA1AHwPYCMBWBTAxsAOgCVsAzbMbKXbAUQEcIBDAGwGcAKAIiaa4IAKTOABkywDgCYYAAgDkADzkBKWTz7KCASShsADngnKA3AFgAUBhz5iZClRoNm7br35DR4qapnqumnX1DDhMgA=
Contributor guide
Assessment
This issue has not been assessed yet.