dotnet / dotnet/dotnet-api-docs

String.PadLeft doesn't allocate on net core in some cases

Open
#8,749 0 comments 0 reactions 0 assignees View on GitHub
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.