Skip to content

[API Proposal]: string.ConstantEmpty #60508

@deeprobin

Description

@deeprobin

Background and motivation

string.Empty is a static readonly empty string. Since this cannot be used in attributes, I would like to suggest that we create a constant version of this.

API Proposal

namespace System
{
    public sealed class String : ICloneable, IComparable, IComparable<string>, IConvertible, IEquatable<string>, System.Collections.Generic.IEnumerable<char>
    {
        // Current:
        public static readonly string Empty = "";

        // Proposal:
        // Naming could also be "ConstEmpty" instead of "ConstantEmpty"
        public const string ConstantEmpty = "";
    }
}

API Usage

[Theory]
[InlineData(string.ConstEmpty)]
// previous: [InlineData("")]
public void MyTest(input) {
    Assert.True(string.IsNullOrEmpty(input));
}

Alternative Designs

No response

Risks

No risks, since only a constant is applied and does not replace the static field.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions