Skip to content

Stringbuilder.Append should have an IFormattable overload #55366

Closed
@jrmoreno1

Description

@jrmoreno1

Background and Motivation

StringBuilder has several overloads, but none of them work with an interpolated string without first turning it into a string. Given that purpose of the StringBuilder is performance, it seems like turning the interpolation into a string first is going to give a performance hit.

Proposed API

namespace System.Text
{
     public sealed class StringBuilder : System.Runtime.Serialization.ISerializable
     {
+        public StringBuilder AppendFormat(IFormattable)
     }
}

Usage Examples

const string lastName = "Moreno";
const string firstName = "John";
var sb = new StringBuilder();
IFormattable name = $"{lastName}, {firstName}";
sb.AppendFormat(name);

-->

Risks

It's possible that the implementation for the overload would be slower than sb.AppendFormat("{0}, {1}", lastName, firstName);

Metadata

Metadata

Assignees

No one assigned

    Labels

    untriagedNew issue has not been triaged by the area owner

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions