付属曞 C 暙準ラむブラリ

C.1 党般

準拠する C# 実装では、特定のセマンティクスを持぀型の最小セットを提䟛する必芁がありたす。 これらの型ずそのメンバヌは、名前空間ず型のアルファベット順に䞀芧衚瀺されたす。 (§C.2) で識別される型ずそのメンバヌの正匏な定矩に぀いおは、ISO/IEC 23271:2012 共通蚀語むンフラストラクチャ (CLI)、Partition IV を参照しおください。基本クラス ラむブラリ (BCL)、拡匵数倀ラむブラリ、および拡匵配列ラむブラリ。この仕様のリファレンスに含たれおいたす。 §C.2 で識別されおいるもの以倖に必芁な型ずそのメンバヌの䞀芧に぀いおは、§C.3 を参照しおください。

泚: CLI のラむブラリ API のサブセットを採甚しおも、CLI 自䜓ぞの䟝存関係は䜜成されたせん。準拠する実装を CLI に基づいお構築したり、タヌゲットにしたりする必芁はありたせん。

このテキストは有益です。

暙準ラむブラリは、準拠する C# 実装に必芁な型ずメンバヌの最小セットを意図しおいたす。 そのため、C# 蚀語仕様で明瀺的に必芁なメンバヌのみが含たれたす。

準拠した C# 実装では、有甚なプログラムを蚘述できる、より広範なラむブラリが提䟛されるこずが期埅されたす。 たずえば、準拠した実装では、次の方法でこのラむブラリを拡匵できたす。

  • 名前空間の远加。
  • 型の远加。
  • むンタヌフェむス以倖の型ぞのメンバヌの远加。
  • 介圚する基底クラスたたはむンタヌフェむスを远加する。
  • 構造䜓ずクラス型を䜿甚するず、远加のむンタヌフェむスが実装されたす。
  • 既存の型ずメンバヌに ( ConditionalAttribute以倖の) 属性を远加する。

情報テキストの末尟。

C.2 ISO/IEC 23271 で定矩されおいる暙準ラむブラリの皮類

泚: 以䞋の䞀郚の struct 型には、 readonly 修食子がありたす。 この修食子は ISO/IEC 23271 のリリヌス時には䜿甚できたせんでしたが、この仕様の実装に準拠するために必芁です。 泚釈

namespace System
{
    public delegate void Action();

    public class ArgumentException : SystemException
    {
        public ArgumentException();
        public ArgumentException(string? message);
        public ArgumentException(string? message, Exception? innerException);
    }

    public class ArgumentOutOfRangeException : ArgumentException
    {
        public ArgumentOutOfRangeException(string? paramName);
        public ArgumentOutOfRangeException(string? paramName, string? message);
    }

    public class ArithmeticException : Exception
    {
        public ArithmeticException();
        public ArithmeticException(string? message);
        public ArithmeticException(string? message, Exception? innerException);
    }

    public abstract class Array : IList, ICollection, IEnumerable
    {
        public int Length { get; }
        public int Rank { get; }
        public int GetLength(int dimension);
    }

    public class ArrayTypeMismatchException : Exception
    {
        public ArrayTypeMismatchException();
        public ArrayTypeMismatchException(string? message);
        public ArrayTypeMismatchException(string? message,
            Exception? innerException);
    }

    [AttributeUsageAttribute(AttributeTargets.All, Inherited = true,
        AllowMultiple = false)]
    public abstract class Attribute
    {
        protected Attribute();
    }

    public enum AttributeTargets
    {
        Assembly = 0x1,
        Module = 0x2,
        Class = 0x4,
        Struct = 0x8,
        Enum = 0x10,
        Constructor = 0x20,
        Method = 0x40,
        Property = 0x80,
        Field = 0x100,
        Event = 0x200,
        Interface = 0x400,
        Parameter = 0x800,
        Delegate = 0x1000,
        ReturnValue = 0x2000,
        GenericParameter = 0x4000,
        All = 0x7FFF
    }

    [AttributeUsageAttribute(AttributeTargets.Class, Inherited = true)]
    public sealed class AttributeUsageAttribute : Attribute
    {
        public AttributeUsageAttribute(AttributeTargets validOn);
        public bool AllowMultiple { get; set; }
        public bool Inherited { get; set; }
        public AttributeTargets ValidOn { get; }
    }

    public readonly struct Boolean { }
    public readonly struct Byte { }
    public readonly struct Char { }
    public readonly struct Decimal { }
    public abstract class Delegate { }

    public class DivideByZeroException : ArithmeticException
    {
        public DivideByZeroException();
        public DivideByZeroException(string? message);
        public DivideByZeroException(string? message, Exception? innerException);
    }

    public readonly struct Double { }

    public abstract class Enum : ValueType
    {
        protected Enum();
    }

    public class Exception
    {
        public Exception();
        public Exception(string? message);
        public Exception(string? message, Exception? innerException);
        public Exception? InnerException { get; }
        public virtual string Message { get; }
    }

    public static class GC { }

    public interface IDisposable
    {
        void Dispose();
    }

    public interface IEquatable<T> where T : allows ref struct
    {
        bool Equals(T? other);
    }

    public interface IFormattable { }

    public sealed class IndexOutOfRangeException : Exception
    {
        public IndexOutOfRangeException();
        public IndexOutOfRangeException(string? message);
        public IndexOutOfRangeException(string? message,
            Exception? innerException);
    }

    public readonly struct Int16 { }
    public readonly struct Int32 { }
    public readonly struct Int64 { }
    public readonly struct IntPtr { }

    public class InvalidCastException : Exception
    {
        public InvalidCastException();
        public InvalidCastException(string? message);
        public InvalidCastException(string? message, Exception? innerException);
    }

    public class InvalidOperationException : Exception
    {
        public InvalidOperationException();
        public InvalidOperationException(string? message);
        public InvalidOperationException(string? message,
            Exception? innerException);
    }

    public class NotSupportedException : Exception
    {
        public NotSupportedException();
        public NotSupportedException(string? message);
        public NotSupportedException(string? message, 
            Exception? innerException);    
    }

    public struct Nullable<T> where T : struct
    {
        public bool HasValue { get; }
        public T Value { get; }
    }

    public class NullReferenceException : Exception
    {
        public NullReferenceException();
        public NullReferenceException(string? message);
        public NullReferenceException(string? message, Exception? innerException);
    }

    public class Object
    {
        public Object();
        ~Object();
        public virtual bool Equals(object? obj);
        public virtual int GetHashCode();
        public Type GetType();
        public virtual string? ToString();
    }

    [AttributeUsageAttribute(AttributeTargets.Class | AttributeTargets.Struct |
        AttributeTargets.Enum | AttributeTargets.Interface |
        AttributeTargets.Constructor | AttributeTargets.Method |
        AttributeTargets.Property | AttributeTargets.Field |
        AttributeTargets.Event | AttributeTargets.Delegate, Inherited = false)]
    public sealed class ObsoleteAttribute : Attribute
    {
        public ObsoleteAttribute();
        public ObsoleteAttribute(string? message);
        public ObsoleteAttribute(string? message, bool error);
        public bool IsError { get; }
        public string? Message { get; }
    }

    public class OutOfMemoryException : Exception
    {
        public OutOfMemoryException();
        public OutOfMemoryException(string? message);
        public OutOfMemoryException(string? message, Exception? innerException);
    }

    public class OverflowException : ArithmeticException
    {
        public OverflowException();
        public OverflowException(string? message);
        public OverflowException(string? message, Exception? innerException);
    }

    public readonly struct SByte { }
    public readonly struct Single { }

    public sealed class StackOverflowException : Exception
    {
        public StackOverflowException();
        public StackOverflowException(string? message);
        public StackOverflowException(string? message, Exception? innerException);
    }

    public sealed class String : IEnumerable<char>, IEnumerable
    {
        public int Length { get; }
        public char this [int index] { get; }
        public static string Format(string format, params object?[] args);
        System.Collections.IEnumerator IEnumerable.GetEnumerator();
        System.Collections.Generic.IEnumerator<char> IEnumerable<char>.GetEnumerator();
    }

    public class SystemException : Exception
    {
        public SystemException();
        public SystemException(string? message);
        public SystemException(string? message, Exception? innerException);
    }

    public abstract class Type : MemberInfo { }

    public sealed class TypeInitializationException : Exception
    {
        public TypeInitializationException(string fullTypeName,
            Exception? innerException);
    }

    public readonly struct UInt16 { }
    public readonly struct UInt32 { }
    public readonly struct UInt64 { }
    public readonly struct UIntPtr { }

    public abstract class ValueType
    {
        protected ValueType();
    }
}

namespace System.Collections
{
    public interface ICollection : IEnumerable
    {
        int Count { get; }
        bool IsSynchronized { get; }
        object SyncRoot { get; }
        void CopyTo(Array array, int index);
    }

    public interface IEnumerable
    {
        IEnumerator GetEnumerator();
    }

    public interface IEnumerator
    {
        object Current { get; }
        bool MoveNext();
        void Reset();
    }

    public interface IList : ICollection, IEnumerable
    {
        bool IsFixedSize { get; }
        bool IsReadOnly { get; }
        object? this [int index] { get; set; }
        int Add(object? value);
        void Clear();
        bool Contains(object? value);
        int IndexOf(object? value);
        void Insert(int index, object? value);
        void Remove(object? value);
        void RemoveAt(int index);
    }
}

namespace System.Collections.Generic
{
    public interface ICollection<T> : IEnumerable<T>
    {
        int Count { get; }
        bool IsReadOnly { get; }
        void Add(T item);
        void Clear();
        bool Contains(T item);
        void CopyTo(T[] array, int arrayIndex);
        bool Remove(T item);
    }

    public interface IEnumerable<T> : IEnumerable
    {
        IEnumerator<T> GetEnumerator();
    }

    public interface IEnumerator<T> : IDisposable, IEnumerator
    {
        T Current { get; }
    }

    public interface IList<T> : ICollection<T>
    {
        T this [int index] { get; set; }
        int IndexOf(T item);
        void Insert(int index, T item);
        void RemoveAt(int index);
    }
}

namespace System.Diagnostics
{
    [AttributeUsageAttribute(AttributeTargets.Method | AttributeTargets.Class,
                             AllowMultiple = true)]
    public sealed class ConditionalAttribute : Attribute
    {
        public ConditionalAttribute(string conditionString);
        public string ConditionString { get; }
    }
}

namespace System.Reflection
{
    public abstract class MemberInfo
    {
        protected MemberInfo();
    }
}

namespace System.Runtime.CompilerServices
{
    public sealed class IndexerNameAttribute : Attribute
    {
        public IndexerNameAttribute(string indexerName);
    }

    public static class Unsafe
    {
        public static ref T NullRef<T>();
        public static bool IsNullRef<T>(ref T source);
    }
}

namespace System.Threading
{
    public static class Monitor
    {
        public static void Enter(object obj);
        public static void Exit(object obj);
    }
}

C.3 暙準ラむブラリの皮類が ISO/IEC 23271 で定矩されおいない

リストに蚘茉されおいるメンバヌを含む次の型は、準拠する暙準ラむブラリで定矩する必芁がありたす。 (これらの型は、ISO/IEC 23271 の将来の゚ディションで定矩される可胜性がありたす)。これらの型の倚くは、䞀芧よりも倚くのメンバヌを䜿甚できる必芁がありたす。

準拠する実装では、拡匵メ゜ッドずしお Task.GetAwaiter() ず Task<TResult>.GetAwaiter() を提䟛できたす。

namespace System
{
    public interface IAsyncDisposable
    {
        System.Threading.Tasks.ValueTask DisposeAsync();
    }

    public abstract class FormattableString : IFormattable { }

    public static class MemoryExtensions
    {
        public static ReadOnlySpan<char> AsSpan (this string? text);
        public static bool SequenceEqual<T> (this Span<T> span, ReadOnlySpan<T> other)
          where T : IEquatable<T>;
        public static bool SequenceEqual<T> (this ReadOnlySpan<T> span,
          ReadOnlySpan<T> other) where T : IEquatable<T>;
    }

    public class OperationCanceledException : Exception
    {
        public OperationCanceledException();
        public OperationCanceledException(string? message);
        public OperationCanceledException(string? message, Exception? innerException);
    }

    /// <summary>
    ///    A read-only value type which represents an abstract
    ///    index to be used with collections.
    ///    - The Index can be relative to the start or end of a
    ///      collection.
    ///    - An Index can be converted to a zero-based concrete
    ///      from-start index to be used with a collection
    ///      of some specified length.
    ///    - Equality between Index values is provided, however
    ///      unlike concrete indices they are not ordered.
    ///    - Array and String element access support indexing
    ///      with Index values.
    /// </summary>
    public readonly struct Index : IEquatable<Index>
    {
        /// <summary>
        ///    Construct an Index from an integer value and a
        ///    boolean indicating whether the value is relative
        ///    to the end (true) or start (false).
        /// </summary>
        /// <param name="value">
        ///    The value, must be ≥ 0.
        /// </param>
        /// <param name="fromEnd">
        ///    Optional boolean indicating whether the Index is
        ///    relative to the end (true) or start (false).
        ///    The default value is false.
        /// </param>
        /// <exception cref="ArgumentOutOfRangeException">
        ///    Thrown if value < 0.
        /// </exception>
        /// <remarks>
        ///    If the Index is relative to the start then:
        ///       - the value 0 refers to the first element.
        ///    If the Index is relative to the end then:
        ///       - the value 1 refers to the last element; and
        ///       - the value 0 refers to beyond last element.
        /// </remarks>
        public Index(int value, bool fromEnd = false);

        /// <summary>
        ///    Implicit conversion from integer to a
        ///    from-start Index.
        /// </summary>
        /// <remarks>
        ///    The predefined operator:
        ///       <c>Index operator ^(int value);</c>
        ///    is provided to convert from integer to a
        ///    from-end Index.
        /// </remarks>
        public static implicit operator Index(int value);

        /// <summary>
        ///    Return the value.
        /// </summary>
        public int Value { get; }

        /// <summary>
        ///    Return whether the Index is relative to
        ///    the end (true) or start (false).
        /// </summary>
        public bool IsFromEnd { get; }

        /// <summary>
        ///    Return a concrete from-start index for a
        ///    given collection length.
        /// </summary>
        /// <param name="length">
        ///    The length of the collection that the index
        ///    will be used with.
        /// </param>
        /// <remarks>
        ///    This method performs no sanity checking and
        ///    will never throw an IndexOutOfRangeException.
        ///    It is expected that the returned index will be
        ///    used with a collection which will do validation.
        /// </remarks>
        public int GetOffset(int length);

        /// <summary>
        ///    Indicates whether the current Index value is
        ///    equal to another Index value.
        /// </summary>
        /// <param name="other">
        ///    The value to compare with this Index.
        /// </param>
        public bool Equals(Index other);
    }

    /// <summary>
    ///    A read-only value type which represents a range of
    ///    abstract indices to be used with collections.
    ///    - The Range has two Index properties, Start and End.
    ///    - A Range can be converted to a concrete index from
    ///      the start and a length value to be used with a
    ///      collection of some specified length.
    ///    - Equality between Range values is provided,
    ///      however they are not ordered.
    ///    - Array and String element access supports indexing
    ///      with Range values, returning a sub-array/substring
    ///      of the indexed value respectively.
    /// </summary>
    public readonly struct Range : IEquatable<Range>
    {
        /// <summary>
        ///    Construct a Range from two Index values.
        /// </summary>
        /// <param name="start">
        ///    The inclusive Index value for the start
        ///    of the range.
        /// </param>
        /// <param name="end">
        ///    The exclusive Index value for the end
        ///    of the range.</param>
        /// <remarks>
        ///    As Index values represent unordered abstract
        ///    indices no sanity checking can be performed
        ///    on the resultant Range value,
        ///    <see cref="GetOffsetAndLength">".
        ///
        ///    The predefined operator:
        ///       <c>Range operator ..(Index start, Index end);</c>
        ///    also exists to create a Range value.
        /// </remarks>
        public Range(Index start, Index end);

        /// <summary>Return the starting Index.</summary>
        public Index Start { get; }

        /// <summary>Return the ending Index.</summary>
        public Index End { get; }

        /// <summary>
        ///    Return a concrete from-start index and the
        ///    range length for a given collection length.
        /// </summary>
        /// <param name="length">
        ///    The length of the collection that the result
        ///    will be used with.
        /// </param>
        /// <exception cref="ArgumentOutOfRangeException">
        ///    Thrown if the range is not valid wrt length.
        /// </exception>
        /// <returns>
        ///    A tuple consisting of an index value and range length
        /// </returns>
        public (int Offset, int Length) GetOffsetAndLength(int length);

        /// <summary>
        ///    Indicates whether the current Range value is equal
        ///    to another Range value.
        /// </summary>
        /// <param name="other">
        ///    The value to compare with this Range.
        /// </param>
        public bool Equals(Range other);
    }

    public readonly ref struct ReadOnlySpan<T>
    {
        public int Length { get; }
        public ref readonly T this[int index] { get; }
    }

    public readonly ref struct Span<T>
    {
        public int Length { get; }
        public ref T this[int index] { get; }
        public static implicit operator ReadOnlySpan<T>(Span<T> span);
    }

    public struct ValueTuple<T1>
    {
        public T1 Item1;
        public ValueTuple(T1 item1);
    }

    public struct ValueTuple<T1, T2>
    {
        public T1 Item1;
        public T2 Item2;
        public ValueTuple(T1 item1, T2 item2);
    }

    public struct ValueTuple<T1, T2, T3>
    {
        public T1 Item1;
        public T2 Item2;
        public T3 Item3;
        public ValueTuple(T1 item1, T2 item2, T3 item3);
    }

    public struct ValueTuple<T1, T2, T3, T4>
    {
        public T1 Item1;
        public T2 Item2;
        public T3 Item3;
        public T4 Item4;
        public ValueTuple(T1 item1, T2 item2, T3 item3, T4 item4);
    }

    public struct ValueTuple<T1, T2, T3, T4, T5>
    {
        public T1 Item1;
        public T2 Item2;
        public T3 Item3;
        public T4 Item4;
        public T5 Item5;
        public ValueTuple(T1 item1, T2 item2, T3 item3, T4 item4, T5 item5);
    }

    public struct ValueTuple<T1, T2, T3, T4, T5, T6>
    {
        public T1 Item1;
        public T2 Item2;
        public T3 Item3;
        public T4 Item4;
        public T5 Item5;
        public T6 Item6;
        public ValueTuple(T1 item1, T2 item2, T3 item3, T4 item4, T5 item5,
            T6 item6);
    }

    public struct ValueTuple<T1, T2, T3, T4, T5, T6, T7>
    {
        public T1 Item1;
        public T2 Item2;
        public T3 Item3;
        public T4 Item4;
        public T5 Item5;
        public T6 Item6;
        public T7 Item7;
        public ValueTuple(T1 item1, T2 item2, T3 item3, T4 item4, T5 item5,
            T6 item6, T7 item7);
    }

    public struct ValueTuple<T1, T2, T3, T4, T5, T6, T7, TRest>
    {
        public T1 Item1;
        public T2 Item2;
        public T3 Item3;
        public T4 Item4;
        public T5 Item5;
        public T6 Item6;
        public T7 Item7;
        public TRest Rest;
        public ValueTuple(T1 item1, T2 item2, T3 item3, T4 item4, T5 item5,
            T6 item6, T7 item7, TRest rest);
    }
}

namespace System.Collections.Generic
{
    public interface IReadOnlyCollection<out T> : IEnumerable<T>
    {
        int Count { get; }
    }

    public interface IReadOnlyList<out T> : IReadOnlyCollection<T>
    {
        T this [int index] { get; }
    }

    public interface IAsyncEnumerable<out T>
    {
        IAsyncEnumerator<T> GetAsyncEnumerator(CancellationToken token = default);
    }

    public interface IAsyncEnumerator<out T> : IAsyncDisposable
    {
        System.Threading.Tasks.ValueTask<bool> MoveNextAsync();
        T Current { get; }
    }
}

namespace System.Diagnostics.CodeAnalysis
{
    [System.AttributeUsage(System.AttributeTargets.Field |
      System.AttributeTargets.Parameter | System.AttributeTargets.Property,
      Inherited=false)]
    public sealed class AllowNullAttribute : Attribute
    {
        public AllowNullAttribute();
    }

    [System.AttributeUsage(System.AttributeTargets.Field |
      System.AttributeTargets.Parameter | System.AttributeTargets.Property,
      Inherited=false)]
    public sealed class DisallowNullAttribute : Attribute
    {
        public DisallowNullAttribute();
    }

    [System.AttributeUsage(System.AttributeTargets.Method, Inherited=false)]
    public sealed class DoesNotReturnAttribute : Attribute
    {
        public DoesNotReturnAttribute();
    }

    [System.AttributeUsage(System.AttributeTargets.Parameter, Inherited=false)]
    public sealed class DoesNotReturnIfAttribute : Attribute
    {
        public DoesNotReturnIfAttribute(bool parameterValue);
    }

    [System.AttributeUsage(System.AttributeTargets.Field | 
      System.AttributeTargets.Parameter | System.AttributeTargets.Property | 
      System.AttributeTargets.ReturnValue, Inherited=false)]
    public sealed class MaybeNullAttribute : Attribute
    {
        public MaybeNullAttribute();
    }

    [System.AttributeUsage(System.AttributeTargets.Parameter, Inherited=false)]
    public sealed class MaybeNullWhenAttribute : Attribute
    {
        public MaybeNullWhenAttribute(bool returnValue);
    }

    [System.AttributeUsage(System.AttributeTargets.Method | 
    System.AttributeTargets.Property, AllowMultiple=true, Inherited=false)]
    public sealed class MemberNotNullAttribute : Attribute
    {
        public MemberNotNullAttribute(string member) {}
        public MemberNotNullAttribute(params string[] members) {}
    }

    [System.AttributeUsage(System.AttributeTargets.Method | 
      System.AttributeTargets.Property, AllowMultiple=true, Inherited=false)]
    public sealed class MemberNotNullWhenAttribute : Attribute
    {
        public MemberNotNullWhenAttribute(bool returnValue, string member) {}
        public MemberNotNullWhenAttribute(bool returnValue, params string[] members) {}
    }

    [System.AttributeUsage(System.AttributeTargets.Field |
      System.AttributeTargets.Parameter | System.AttributeTargets.Property | 
      System.AttributeTargets.ReturnValue, Inherited=false)]
    public sealed class NotNullAttribute : Attribute
    {
        public NotNullAttribute();
    }

    [System.AttributeUsage(System.AttributeTargets.Parameter | 
      System.AttributeTargets.Property | System.AttributeTargets.ReturnValue, 
      AllowMultiple=true, Inherited=false)]
    public sealed class NotNullIfNotNullAttribute : Attribute
    {
        public NotNullIfNotNullAttribute(string parameterName);
    }

    [System.AttributeUsage(System.AttributeTargets.Parameter, Inherited=false)]
    public sealed class NotNullWhenAttribute : Attribute
    {
        public NotNullWhenAttribute(bool returnValue);
    }

    [System.AttributeUsage(System.AttributeTargets.Method
      | System.AttributeTargets.Parameter
      | System.AttributeTargets.Property,
      AllowMultiple=false, Inherited=false)]
    public sealed class UnscopedRefAttribute : Attribute
    {
        public UnscopedRefAttribute();
    }

    [System.AttributeUsage(System.AttributeTargets.Constructor,
      AllowMultiple=false, Inherited=false)]
    public sealed class SetsRequiredMembersAttribute : Attribute
    {
        public SetsRequiredMembersAttribute() {}
    }
}

namespace System.Linq.Expressions
{
    public sealed class Expression<TDelegate>
    {
        public TDelegate Compile();
        public static UnaryExpression NegateChecked(Expression expression,
            MethodInfo? method);
        public static BinaryExpression AddChecked(Expression left,
            Expression right, MethodInfo? method);
        public static BinaryExpression SubtractChecked(Expression left,
            Expression right, MethodInfo? method);
        public static BinaryExpression MultiplyChecked(Expression left,
            Expression right, MethodInfo? method);
        public static UnaryExpression ConvertChecked(Expression expression,
            Type type, MethodInfo? method);
    }
}

namespace System.Runtime.CompilerServices
{
    [System.AttributeUsage(System.AttributeTargets.Class
      | System.AttributeTargets.Interface
      | System.AttributeTargets.Struct, Inherited=false)]
    public sealed class CollectionBuilderAttribute : System.Attribute
    {
        public CollectionBuilderAttribute(Type builderType, string methodName);
        public Type BuilderType { get; }
        public string MethodName { get; }
    }

    public ref struct DefaultInterpolatedStringHandler
    {
        public DefaultInterpolatedStringHandler(int literalLength,
            int formattedCount);
        public DefaultInterpolatedStringHandler(int literalLength,
            int formattedCount, IFormatProvider? provider);
        public DefaultInterpolatedStringHandler(int literalLength,
            int formattedCount, IFormatProvider? provider, Span<char> initialBuffer);
        public void AppendFormatted(scoped ReadOnlySpan<char> value);
        public void AppendFormatted(string? value);
        public void AppendFormatted(object? value, int alignment = 0,
            string? format = default);
        public void AppendFormatted(scoped ReadOnlySpan<char> value,
            int alignment = 0, string? format = default);
        public void AppendFormatted(string? value, int alignment = 0,
            string? format = default);
        public void AppendFormatted<T>(T value);
        public void AppendFormatted<T>(T value, int alignment);
        public void AppendFormatted<T>(T value, string? format);
        public void AppendFormatted<T>(T value, int alignment, string? format);
        public void AppendLiteral(string value);
        public override string ToString();
        public string ToStringAndClear();
    }

    [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | 
        AttributeTargets.Interface | AttributeTargets.Method,
        Inherited = false, AllowMultiple = false)]
    public sealed class AsyncMethodBuilderAttribute : Attribute
    {
        public AsyncMethodBuilderAttribute(Type builderType);
 
        public Type BuilderType { get; }
    }

    [AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false,
        Inherited = false)]
    public sealed class CallerArgumentExpressionAttribute : Attribute
    {
        public CallerArgumentExpressionAttribute(string parameterName);
    }

    [AttributeUsage(AttributeTargets.Parameter, Inherited = false)]
    public sealed class CallerFilePathAttribute : Attribute
    {
        public CallerFilePathAttribute();
    }

    [AttributeUsage(AttributeTargets.Parameter, Inherited = false)]
    public sealed class CallerLineNumberAttribute : Attribute
    {
        public CallerLineNumberAttribute();
    }

    [AttributeUsage(AttributeTargets.Parameter, Inherited = false)]
    public sealed class CallerMemberNameAttribute : Attribute
    {
        public CallerMemberNameAttribute();
    }

    [System.AttributeUsage(System.AttributeTargets.Parameter, Inherited=false)]
    public sealed class EnumeratorCancellationAttribute : Attribute
    {
        public EnumeratorCancellationAttribute();
    }
    
    public static class FormattableStringFactory
    {
        public static FormattableString Create(string format,
            params object?[] arguments);
    }

    public interface ICriticalNotifyCompletion : INotifyCompletion
    {
        void UnsafeOnCompleted(Action continuation);
    }

    [AttributeUsage(AttributeTargets.Struct, AllowMultiple=false)]
    public sealed class InlineArrayAttribute : Attribute
    {
        public InlineArrayAttribute(int length);

        public int Length { get; }
    }

    public interface INotifyCompletion
    {
        void OnCompleted(Action continuation);
    }

    [System.AttributeUsage(System.AttributeTargets.Parameter,
        AllowMultiple=false, Inherited=false)]
    public sealed class InterpolatedStringHandlerArgumentAttribute : Attribute
    {
        public InterpolatedStringHandlerArgumentAttribute(string argument);
        public InterpolatedStringHandlerArgumentAttribute(params string[] arguments);
    }

    [System.AttributeUsage(System.AttributeTargets.Class |
        System.AttributeTargets.Struct, AllowMultiple=false, Inherited=false)]
    public sealed class InterpolatedStringHandlerAttribute : Attribute
    {
        public InterpolatedStringHandlerAttribute ();
    }

    /// <summary>
    ///    Provides indexed access to the elements of a
    ///    tuple-like value at runtime. This interface is
    ///    used by the language to implement positional
    ///    pattern matching (§11.2.5) when no static
    ///    tuple type or <c>Deconstruct</c> method is
    ///    available.
    /// </summary>
    public interface ITuple
    {
        /// <summary>
        ///    The number of elements in the tuple.
        /// </summary>
        /// <remarks>
        ///    The value returned shall be non-negative,
        ///    and shall not change for the lifetime of
        ///    the instance.
        /// </remarks>
        int Length { get; }

        /// <summary>
        ///    Returns the element at the specified
        ///    zero-based position.
        /// </summary>
        /// <param name="index">
        ///    The zero-based position of the element
        ///    to return; shall be ≥ 0 and &lt; <see cref="Length"/>.
        /// </param>
        /// <exception cref="IndexOutOfRangeException">
        ///    Thrown if <paramref name="index"/> is
        ///    outside the range
        ///    <c>[0, Length)</c>.
        /// </exception>
        object? this[int index] { get; }
    [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
    public sealed class ModuleInitializerAttribute : Attribute
    {
        public ModuleInitializerAttribute() { }
    }

    [System.AttributeUsage(System.AttributeTargets.Constructor
    | System.AttributeTargets.Method | System.AttributeTargets.Property,
      AllowMultiple=false, Inherited=false)]
    public sealed class OverloadResolutionPriorityAttribute : Attribute
    {
        public OverloadResolutionPriorityAttribute(int priority) {}
    }

    [System.AttributeUsage(System.AttributeTargets.Class |
      System.AttributeTargets.Field | System.AttributeTargets.Property |
      System.AttributeTargets.Struct, AllowMultiple=false, Inherited=false)]
    public sealed class RequiredMemberAttribute : Attribute
    {
        public RequiredMemberAttribute() {}
    }

    public readonly struct TaskAwaiter : ICriticalNotifyCompletion,
        INotifyCompletion
    {
        public bool IsCompleted { get; }
        public void GetResult();
    }

    public readonly struct TaskAwaiter<TResult> : ICriticalNotifyCompletion,
        INotifyCompletion
    {
        public bool IsCompleted { get; }
        public TResult GetResult();
    }

    [System.AttributeUsage(System.AttributeTargets.Method, Inherited=false)]
    public sealed class UnmanagedCallersOnlyAttribute : Attribute
    {
        public UnmanagedCallersOnlyAttribute ();
        public Type[]? CallConvs;
        public string? EntryPoint;
    }

    public readonly struct ValueTaskAwaiter : ICriticalNotifyCompletion,
        INotifyCompletion
    {
        public bool IsCompleted { get; }
        public void GetResult();
    }

    public readonly struct ValueTaskAwaiter<TResult>
        : ICriticalNotifyCompletion, INotifyCompletion
    {
        public bool IsCompleted { get; }
        public TResult GetResult();
    }
}

namespace System.Threading
{
    public class CancellationTokenSource : IDisposable
    {
        public CancellationTokenSource();
        public System.Threading.CancellationToken Token { get; }
        public void Cancel();
        public static CancellationTokenSource CreateLinkedTokenSource
                                             (CancellationToken token1,
                                              CancellationToken token2);
    }

    public readonly struct CancellationToken : IEquatable<CancellationToken>
    {
        public bool IsCancellationRequested { get; }
    }

    public sealed class Lock
    {
        public Lock();
        public System.Threading.Lock.Scope EnterScope();
        public ref struct Lock.Scope
        {
            public void Dispose();
        }
    }
}

namespace System.Threading.Tasks
{
    public class Task
    {
        public System.Runtime.CompilerServices.TaskAwaiter GetAwaiter();
    }

    public class Task<TResult> : Task
    {
        public new System.Runtime.CompilerServices.TaskAwaiter<TResult> GetAwaiter();
    }

    public readonly struct ValueTask : System.IEquatable<ValueTask>
    {
        public System.Runtime.CompilerServices.ValueTaskAwaiter GetAwaiter();
    }

    public readonly struct ValueTask<TResult>
        : System.IEquatable<ValueTask<TResult>>
    {
        public new System.Runtime.CompilerServices.ValueTaskAwaiter<TResult>
            GetAwaiter();
    }
}

C.4 圢匏の仕様

挿入文字列匏 (§12.8.3) で䜿甚される曞匏の意味は、ISO/IEC 23271:2012 で定矩されおいたす。 䟿宜䞊、 System.IFormattableの説明から次のテキストがコピヌされたす。

このテキストは有益です。

format は、オブゞェクトが文字列に倉換されたずきの倖芳を衚す文字列です。 暙準圢匏たたはカスタム圢匏を䜿甚できたす。 暙準圢匏は Axx ずいう圢匏になりたす。ここで、 A は format specifier ず呌ばれる 1 文字の英字で、 xx は 0 から 99 たでの敎数で、 precision 指定子ず呌ばれたす。 曞匏指定子は、文字列ずしお衚される倀に適甚される曞匏蚭定の皮類を制埡したす。 precision 指定子は、文字列内の有効桁数たたは小数点以䞋桁数 (該圓する堎合) を制埡したす。

泚: 暙準曞匏指定子の䞀芧に぀いおは、次の衚を参照しおください。 System.Int32などの特定のデヌタ型では、1 ぀以䞊の暙準曞匏指定子がサポヌトされない堎合があるこずに泚意しおください。 泚釈

泚: 曞匏にカルチャによっお異なる蚘号 ('C' 圢匏や 'c' 圢匏に含たれる currencysymbol など) が含たれおいる堎合、曞匏蚭定オブゞェクトは文字列衚珟で䜿甚される実際の文字を提䟛したす。 メ゜ッドには、曞匏蚭定オブゞェクトを提䟛する System.IFormatProvider オブゞェクトを枡すパラメヌタヌが含たれおいる堎合や、珟圚のカルチャのシンボル定矩を含む既定の曞匏蚭定オブゞェクトを䜿甚する堎合がありたす。 珟圚のカルチャでは、通垞、既定でシステム党䜓で䜿甚されおいるのず同じシンボル セットが䜿甚されたす。 基本クラス ラむブラリでは、システム指定の数倀型の曞匏蚭定オブゞェクトは System.Globalization.NumberFormatInfo むンスタンスです。 System.DateTimeむンスタンスの堎合は、System.Globalization.DateTimeFormatInfoが䜿甚されたす。 泚釈

次の衚では、基本クラス ラむブラリの数倀デヌタ型で䜿甚される暙準曞匏指定子ず関連する曞匏蚭定オブゞェクト メンバヌに぀いお説明したす。

曞匏指定子 説明

C

c

通貚圢匏: 通貚倀を含む文字列に䜿甚されたす。 System.Globalization.NumberFormatInfo.CurrencySymbolのSystem.Globalization.NumberFormatInfo.CurrencyGroupSizes、System.Globalization.NumberFormatInfo.CurrencyGroupSeparator、System.Globalization.NumberFormatInfo.CurrencyDecimalSeparator、およびSystem.Globalization.NumberFormatInfoメンバヌは、それぞれ通貚蚘号、数字グルヌプのサむズず区切り蚘号、および小数点を指定したす。

System.Globalization.NumberFormatInfo.CurrencyNegativePattern ず System.Globalization.NumberFormatInfo.CurrencyPositivePattern 負の倀ず正の倀を衚すために䜿甚される蚘号を決定したす。 たずえば、負の倀の前にマむナス蚘号を付けたり、かっこで囲んだりするこずができたす。

粟床指定子を省略するず、 System.Globalization.NumberFormatInfo.CurrencyDecimalDigits は文字列内の小数点以䞋の桁数を決定したす。 必芁に応じお、結果は最も近い衚珟可胜な倀に䞞められたす。

D

d

Decimal Format: (この圢匏は敎数デヌタ型で指定されおいる堎合にのみ有効です)。敎数倀を含む文字列に䜿甚されたす。 負の数倀には、 System.Globalization.NumberFormatInfo.NegativeSign プロパティで指定された負の数倀蚘号が付きたす。

粟床指定子は、文字列に衚瀺される最小桁数を決定したす。 指定した有効桁数に含たれる数倀よりも倚くの桁数が必芁な堎合、文字列はれロで巊に埋められたす。 有効桁数指定子が指定する桁数が倀よりも少ない堎合、有効桁数指定子は無芖されたす。

E

e

ç§‘å­Š (゚ンゞニアリング) 圢匏: 次のいずれかの圢匏の文字列に䜿甚されたす。

          [-]m.dddddddE +xxx

          [-]m.dddddddE-xxx

          [-]m.dddddd e+xxx

          [-]m.dddddde-xxx

負の数倀蚘号 ('-') は、倀が負の倀であり、 System.Globalization.NumberFormatInfo.NegativeSign プロパティによっお提䟛される堎合にのみ衚瀺されたす。

0 以倖の 10 進数 (m) が小数点 ('.') の前に眮き、 System.Globalization.NumberFormatInfo.NumberDecimalSeparator プロパティによっお指定されたす。

粟床指定子は、文字列内の小数点以䞋の桁数 (ddddddd) を決定したす。 有効桁数指定子を省略するず、小数点以䞋 6 桁が文字列に含たれたす。

指数 (+/-xxx) は、正たたは負の数の蚘号の埌に 3 桁以䞊 (xxx) で構成されたす。 指数は、必芁に応じおれロで巊に埋められたす。 曞匏指定子 ('E' たたは 'e') の倧文字ず小文字は、文字列の指数プレフィックス (E たたは e) に䜿甚されるケヌスを決定したす。 必芁に応じお、結果は最も近い衚珟可胜な倀に䞞められたす。 正の数倀蚘号は、 System.Globalization.NumberFormatInfo.PositiveSign プロパティによっお指定されたす。

F

f

固定小数点圢匏: 次の圢匏の文字列に䜿甚されたす。

          [-]m.dd...d

0 以倖の 10 進数 (m) の前に小数点 ('.') が 1 ぀以䞊付いおいたす。これは、 System.Globalization.NumberFormatInfo.NumberDecimalSeparator プロパティによっお提䟛されたす。

負の数倀蚘号 ('-') は、倀が負の堎合にのみm の前にありたす。 このシンボルは、 System.Globalization.NumberFormatInfo.NegativeSign プロパティによっお提䟛されたす。

粟床指定子は、小数点以䞋の桁数 (dd...d) を指定したす。 粟床指定子を省略するず、 System.Globalization.NumberFormatInfo.NumberDecimalDigits は文字列内の小数点以䞋の桁数を決定したす。 必芁に応じお、結果は最も近い衚珟可胜な倀に䞞められたす。

G

g

General Format: 文字列は、固定小数点圢匏 ('F' たたは 'f') たたは科孊圢匏 ('E' たたは 'e') で曞匏蚭定されたす。

敎数型の堎合:

exponent<粟床指定子の堎合、倀は固定小数点圢匏を䜿甚しお曞匏蚭定されたす。ここで、exponent は指数圢匏の倀の指数です。 その他のすべおの倀には、科孊的な圢匏が䜿甚されたす。

粟床指定子を省略するず、デヌタ型の最倧倀を衚瀺するために必芁なフィヌルド幅ず同じ既定の有効桁数が䜿甚され、その結果、倀が固定小数点圢匏で曞匏蚭定されたす。 敎数型の既定の有効桁数は次のずおりです。

           System.Int16、 System.UInt16 : 5

           System.Int32、 System.UInt32 : 10

           System.Int64、 System.UInt64 : 19

Single 型、Decimal 型、Double 型の堎合:

exponent ≥ -4 および exponent< 粟床指定子の堎合、倀は固定小数点圢匏で曞匏蚭定されたす。ここでexponentは指数圢匏の倀の指数です。 その他のすべおの倀には、科孊的な圢匏が䜿甚されたす。 必芁に応じお、結果は最も近い衚珟可胜な倀に䞞められたす。

粟床指定子を省略するず、次の既定の有効桁数が䜿甚されたす。

           System.Single : 7

           System.Double : 15

           System.Decimal : 29

すべおの型の堎合:

  • 結果に衚瀺される桁数 (指数を含たない) は、有効桁数指定子の倀を超えなくなりたす。倀は必芁に応じお䞞められたす。
  • 小数点ず小数点の埌の末尟のれロは、可胜な限り削陀されたす。
  • 曞匏指定子 ('G' たたは 'g' の堎合) は、'E' たたは 'e' が指数指数の前に付くかどうかを決定したす。

N

n

数倀圢匏: 次の圢匏の文字列に䜿甚されたす。

          [-]d,ddd,ddd.dd...d

負の倀の衚珟は、 System.Globalization.NumberFormatInfo.NumberNegativePattern プロパティによっお決たりたす。 パタヌンに負の数の蚘号 ('-') が含たれおいる堎合、このシンボルは System.Globalization.NumberFormatInfo.NegativeSign プロパティによっお提䟛されたす。

少なくずも 0 以倖の 10 進数 (d) の前に小数点 ('.') があり、 System.Globalization.NumberFormatInfo.NumberDecimalSeparator プロパティによっお提䟛されたす。 小数点ず倀の最䞊䜍桁の間の数字は、 System.Globalization.NumberFormatInfo.NumberGroupSizes プロパティで指定されたグルヌプ サむズを䜿甚しおグルヌプ化されたす。 グルヌプ区切り蚘号 (',') は、各桁グルヌプの間に挿入され、 System.Globalization.NumberFormatInfo.NumberGroupSeparator プロパティによっお提䟛されたす。

粟床指定子は、小数点以䞋の桁数 (dd...d)。 粟床指定子を省略するず、 System.Globalization.NumberFormatInfo.NumberDecimalDigits は文字列内の小数点以䞋の桁数を決定したす。 必芁に応じお、結果は最も近い衚珟可胜な倀に䞞められたす。

P

p

パヌセント圢匏: パヌセンテヌゞを含む文字列に䜿甚されたす。 System.Globalization.NumberFormatInfo.PercentSymbolのSystem.Globalization.NumberFormatInfo.PercentGroupSizes、System.Globalization.NumberFormatInfo.PercentGroupSeparator、System.Globalization.NumberFormatInfo.PercentDecimalSeparator、およびSystem.Globalization.NumberFormatInfoメンバヌは、それぞれパヌセント蚘号、数字グルヌプのサむズず区切り蚘号、および小数点を指定したす。

System.Globalization.NumberFormatInfo.PercentNegativePattern ず System.Globalization.NumberFormatInfo.PercentPositivePattern 負の倀ず正の倀を衚すために䜿甚される蚘号を決定したす。 たずえば、負の倀の前にマむナス蚘号を付けたり、かっこで囲んだりするこずができたす。

有効桁数が指定されおいない堎合、結果の小数点以䞋の桁数は System.Globalization.NumberFormatInfo.PercentDecimalDigitsによっお決たりたす。 必芁に応じお、結果は最も近い衚珟可胜な倀に䞞められたす。

結果は 100 でスケヌリングされたす (.99 は 99% になりたす)。

R

r

ラりンド トリップ圢匏: (この圢匏は、 System.Double たたは System.Singleで指定した堎合にのみ有効です)。浮動小数点倀の文字列衚珟の粟床が、文字列を解析しおも元の倀ず比范しおも粟床が䜎䞋しないようにするために䜿甚されたす。 デヌタ型の最倧有効桁数 ( System.Singleの堎合は 7、 System.Doubleの堎合は 15) の堎合、粟床は小数点以䞋 2 桁増加したす。 粟床指定子がこの曞匏指定子ず共に指定された堎合、それは無芖されたす。 それ以倖の堎合、この圢匏は固定小数点圢匏ず同じです。

X

x

16 進数圢匏: (この圢匏は敎数デヌタ型で指定されおいる堎合にのみ有効です)。Base 16 の数倀の文字列衚珟に䜿甚されたす。有効桁数によっお、文字列内の最小桁数が決たりたす。 有効桁数が数倀に含たれおいる桁数より倚く指定されおいる堎合、数倀はれロで巊に埋め蟌たれたす。 曞匏指定子 ('X' たたは 'x') の倧文字ず小文字のどちらが 16 進数衚珟で䜿甚されるかが決たりたす。

数倀がSystem.Single、System.Double、たたはNaNの倀を持぀PositiveInfinityたたはNegativeInfinityの堎合、曞匏指定子は無芖され、System.Globalization.NumberFormatInfo.NaNSymbol、System.Globalization.NumberFormatInfo.PositiveInfinitySymbol、たたはSystem.Globalization.NumberFormatInfo.NegativeInfinitySymbolのいずれかが返されたす。

カスタム曞匏は、䞊蚘の暙準曞匏指定文字列 (Axx) の圢匏ではない曞匏ずしお指定された任意の文字列です。 次の衚では、カスタム圢匏の構築に䜿甚される文字に぀いお説明したす。

曞匏指定子 説明
0 (れロ)

れロ プレヌスホルダヌ: 曞匏蚭定䞭の倀がカスタム圢匏で '0' が衚瀺される䜍眮に数字がある堎合、その数字は出力文字列にコピヌされたす。それ以倖の堎合は、出力文字列内のその䜍眮に 0 が栌玍されたす。 小数点区切り蚘号の前の巊端の '0' の䜍眮、および小数点区切り蚘号の埌の右端の '0' の䜍眮によっお、出力文字列に垞に存圚する桁数の範囲が決たりたす。

小数点区切り蚘号の埌のれロたたは数字のプレヌスホルダヌの数によっお、小数点の埌に衚瀺される桁数が決たりたす。 倀は必芁に応じお䞞められたす。

#

Digit placeholder: 曞匏蚭定されおいる倀の '#' がカスタム圢匏で衚瀺される䜍眮に数字がある堎合、その数字は出力文字列にコピヌされたす。それ以倖の堎合、出力文字列内のその䜍眮には䜕も栌玍されたせん。 この指定子は、'0' が文字列内の唯䞀の数字である堎合でも、有効な数字でない堎合は 、'0' 文字を栌玍しないこずに泚意しおください。 (有効な数字の堎合は、出力文字列に '0' 文字が衚瀺されたす)。

小数点区切り蚘号の埌のれロたたは数字のプレヌスホルダヌの数によっお、小数点の埌に衚瀺される桁数が決たりたす。 倀は必芁に応じお䞞められたす。

. (期間) 小数点区切り蚘号: 巊端の '.' 曞匏指定文字列内の文字は、曞匏蚭定された倀の小数点区切り蚘号の䜍眮を決定したす。远加の '.' 文字は無芖されたす。 System.Globalization.NumberFormatInfo.NumberDecimalSeparator プロパティは、小数点区切り蚘号ずしお䜿甚される蚘号を決定したす。
, (コンマ)

グルヌプ区切り蚘号ず数倀のスケヌリング: ',' 文字は 2 ぀の目的を果たしたす。 最初に、カスタム圢匏に 2 ぀のれロたたは数字のプレヌスホルダヌ (0 たたは #) の間にこの文字が含たれおいる堎合、小数点区切り蚘号が存圚する堎合は、小数点区切り蚘号の巊偎に各桁の間にグルヌプ区切り蚘号が挿入されたす。 System.Globalization.NumberFormatInfo.NumberGroupSeparatorプロパティずSystem.Globalization.NumberFormatInfo.NumberGroupSizesプロパティによっお、グルヌプ区切り蚘号ずしお䜿甚される蚘号ず、各グルヌプの桁数がそれぞれ決たりたす。

曞匏指定文字列に小数点の巊に 1 ぀以䞊の ',' 文字が含たれおいる堎合、数倀は拡倧瞮小されたす。 小数点以䞋桁数は、小数点区切り蚘号のすぐ巊にあるグルヌプ区切り文字の数によっお決たりたす。 x 文字がある堎合、倀は曞匏蚭定される前に 1000X で陀算されたす。 たずえば、曞匏指定文字列 '0,' は倀を 100 䞇で陀算したす。 スケヌリングを瀺す ',' 文字が存圚しおも、出力文字列にグルヌプ区切り蚘号は挿入されないこずに泚意しおください。 したがっお、数倀を 100 䞇単䜍でスケヌリングし、グルヌプ区切り蚘号を挿入するには、'#,##0,' のようなカスタム圢匏を䜿甚したす。

% (パヌセント) パヌセンテヌゞ プレヌスホルダヌ: カスタム圢匏の '%' 文字が存圚するず、曞匏蚭定される前に数倀に 100 が乗算されたす。 パヌセント蚘号は、曞匏指定文字列の '%' が衚瀺される堎所の出力文字列に挿入されたす。 System.Globalization.NumberFormatInfo.PercentSymbolプロパティは、パヌセント蚘号を決定したす。

E0

E+0

E-0

e0

e+0

e-0

゚ンゞニアリング圢匏: 文字列 'E'、'E+'、'E'、'e'、'e+'、たたは 'e-' のいずれかがカスタム圢匏で存圚し、その盎埌に少なくずも 1 ぀の '0' 文字が続く堎合、倀は科孊的衚蚘を䜿甚しお曞匏蚭定されたす。 指数プレフィックス (E たたは e) の埌に続く '0' 文字の数によっお、指数の最小桁数が決たりたす。 'E+' 圢匏ず 'e+' 圢匏は、正たたは負の数倀蚘号が垞に指数の前にあるこずを瀺したす。 'E'、'E'、'e'、たたは 'e-' 圢匏は、負の数の蚘号が負の指数の前にあるこずを瀺したす。正の指数の前に蚘号がありたせん。 正の数倀蚘号は、 System.Globalization.NumberFormatInfo.PositiveSign プロパティによっお指定されたす。 負の数の蚘号は、 System.Globalization.NumberFormatInfo.NegativeSign プロパティによっお指定されたす。
\ (円蚘号) ゚スケヌプ文字: C# などの䞀郚の蚀語では、円蚘号文字によっお、カスタム圢匏の次の文字が゚スケヌプ シヌケンスずしお解釈されたす。 これは、'\n' (改行) などの C 蚀語の曞匏蚭定シヌケンスで䜿甚されたす。 䞀郚の蚀語では、リテラルずしお䜿甚する堎合、゚スケヌプ文字自䜓の前に゚スケヌプ文字を付ける必芁がありたす。 それ以倖の堎合、コンパむラは文字を゚スケヌプ シヌケンスずしお解釈したす。 この゚スケヌプ文字は、すべおのプログラミング蚀語でサポヌトされおいる必芁はありたせん。

'ABC'

"ABC"

リテラル文字列: 単䞀匕甚笊たたは二重匕甚笊で囲たれた文字は、リテラル圢匏で出力文字列にコピヌされ、曞匏蚭定には圱響したせん。
; (セミコロン) セクション区切り蚘号: ';' 文字は、曞匏指定文字列内の正、負、およびれロの数倀のセクションを区切るために䜿甚されたす。 (この機胜に぀いおは、以䞋で詳しく説明したす)。
その他 その他のすべおの文字: 他のすべおの文字は、衚瀺される䜍眮のリテラルずしお出力文字列に栌玍されたす。

固定小数点曞匏指定文字列 ('E0'、'E+0'、'E-0'、'e0'、'e+0'、たたは 'e-0' を含たない文字列) の堎合、小数点区切り蚘号の右偎にれロたたは桁のプレヌスホルダヌがある数の小数点以䞋に数倀が䞞められたす。 ナヌザヌ蚭定の曞匏に小数点が含たれおいない堎合、数倀は最も近い敎数に䞞められたす。 数倀の桁数が、小数点の巊偎にれロたたは数字のプレヌスホルダヌよりも倚い堎合、䜙分な数字は、最初のれロたたは数字のプレヌスホルダヌの盎前の出力文字列にコピヌされたす。

カスタム曞匏には、セクション区切り文字で区切られた最倧 3 ぀のセクションを含めるこずができたす。正、負、れロの倀に異なる曞匏を指定できたす。 セクションは次のように解釈されたす。

  • 1 ぀のセクション: カスタム圢匏はすべおの倀 (正、負、れロ) に適甚されたす。 負の倀には負の笊号が含たれたす。

  • 2 ぀のセクション: 最初のセクションは正の倀ず 0 に適甚され、2 番目のセクションは負の倀に適甚されたす。 曞匏蚭定する倀が負の倀で、2 番目のセクションの曞匏に埓っお䞞めた埌に 0 になる堎合、結果の 0 は最初のセクションに埓っお曞匏蚭定されたす。 負の倀には、負の倀の衚珟を完党に制埡するための負の笊号は含たれたせん。 たずえば、負の倀は、'####.# のようなカスタム圢匏を䜿甚しおかっこで衚すこずができたす。(####.####)’.

  • 3 ぀のセクション: 最初のセクションは正の倀に適甚され、2 番目のセクションは負の倀に適甚され、3 番目のセクションはれロに適甚されたす。 2 番目のセクションは空にするこずができたす (セミコロンの間には䜕も衚瀺されたせん)。この堎合、最初のセクションはすべおの 0 以倖の倀に適甚され、負の倀には負の笊号が含たれたす。 曞匏蚭定する数倀が 0 以倖で、1 番目たたは 2 番目のセクションの曞匏に埓っお䞞めた埌に 0 になる堎合、結果の 0 は 3 番目のセクションに埓っお曞匏蚭定されたす。

System.Enum型ずSystem.DateTime型では、曞匏指定子を䜿甚しお倀の文字列圢匏を曞匏蚭定するこずもできたす。 特定の曞匏指定子の意味は、曞匏蚭定されるデヌタの皮類 (数倀、日付/時刻、列挙) によっお異なりたす。 各型でサポヌトされおいる曞匏指定子の包括的な䞀芧に぀いおは、 System.Enum ず System.Globalization.DateTimeFormatInfo を参照しおください。

C.5 ラむブラリの皮類の省略圢

この仕様では、次のラむブラリの皮類が参照されおいたす。 グロヌバル名前空間修食子を含む、これらの型の完党な名前を次に瀺したす。 この仕様では、これらの型は完党修食名ずしお衚瀺されたす。グロヌバル名前空間修食子を省略した堎合。たたは単玔な非修食型名ずしお、名前空間も省略したす。 たずえば、この仕様で䜿甚する堎合、型 ICollection<T>は垞に型 global::System.Collections.Generic.ICollection<T>を意味したす。

  • global::System.Action
  • global::System.ArgumentException
  • global::System.ArgumentOutOfRangeException
  • global::System.ArithmeticException
  • global::System.Array
  • global::System.ArrayTypeMismatchException
  • global::System.Attribute
  • global::System.AttributeTargets
  • global::System.AttributeUsageAttribute
  • global::System.Boolean
  • global::System.Byte
  • global::System.Char
  • global::System.Decimal
  • global::System.Delegate
  • global::System.DivideByZeroException
  • global::System.Double
  • global::System.Enum
  • global::System.Exception
  • global::System.FormattableString
  • global::System.GC
  • global::System.IAsyncDisposable
  • global::System.IDisposable
  • global::System.IEquatable<T>
  • global::System.IFormattable
  • global::System.Index
  • global::System.IndexOutOfRangeException
  • global::System.Int16
  • global::System.Int32
  • global::System.Int64
  • global::System.IntPtr
  • global::System.InvalidCastException
  • global::System.InvalidOperationException
  • global::System.MemoryExtensions
  • global::System.NotSupportedException
  • global::System.Nullable<T>
  • global::System.NullReferenceException
  • global::System.Object
  • global::System.ObsoleteAttribute
  • global::System.OperationCanceledException
  • global::System.OutOfMemoryException
  • global::System.OverflowException
  • global::System.Range
  • global::System.ReadOnlySpan
  • global::System.SByte
  • global::System.Single
  • global::System.Span
  • global::System.StackOverflowException
  • global::System.String
  • global::System.SystemException
  • global::System.Type
  • global::System.TypeInitializationException
  • global::System.UInt16
  • global::System.UInt32
  • global::System.UInt64
  • global::System.UIntPtr
  • global::System.ValueTuple<T1>
  • global::System.ValueTuple<T1, T2>
  • global::System.ValueTuple<T1, T2, T3>
  • global::System.ValueTuple<T1, T2, T3, T4>
  • global::System.ValueTuple<T1, T2, T3, T4, T5>
  • global::System.ValueTuple<T1, T2, T3, T4, T5, T6>
  • global::System.ValueTuple<T1, T2, T3, T4, T5, T6, T7>
  • global::System.ValueTuple<T1, T2, T3, T4, T5, T6, T7, TRest>
  • global::System.ValueType
  • global::System.Collections.ICollection
  • global::System.Collections.IEnumerable
  • global::System.Collections.IEnumerator
  • global::System.Collections.IList
  • global::System.Collections.Generic.IAsyncEnumerable<out T>
  • global::System.Collections.Generic.IAsyncEnumerator<out T>
  • global::System.Collections.Generic.ICollection<T>
  • global::System.Collections.Generic.IEnumerable<T>
  • global::System.Collections.Generic.IEnumerator<T>
  • global::System.Collections.Generic.IList<T>
  • global::System.Collections.Generic.IReadOnlyCollection<out T>
  • global::System.Collections.Generic.IReadOnlyList<out T>
  • global::System.Diagnostics.ConditionalAttribute
  • global::System.Diagnostics.CodeAnalysis.AllowNullAttribute
  • global::System.Diagnostics.CodeAnalysis.DisallowNullAttribute
  • global::System.Diagnostics.CodeAnalysis.DoesNotReturnAttribute
  • global::System.Diagnostics.CodeAnalysis.DoesNotReturnIfAttribute
  • global::System.Diagnostics.CodeAnalysis.MaybeNullAttribute
  • global::System.Diagnostics.CodeAnalysis.MaybeNullWhenAttribute
  • global::System.Diagnostics.CodeAnalysis.MemberNotNullAttribute
  • global::System.Diagnostics.CodeAnalysis.MemberNotNullWhenAttribute
  • global::System.Diagnostics.CodeAnalysis.NotNullAttribute
  • global::System.Diagnostics.CodeAnalysis.NotNullIfNotNullAttribute
  • global::System.Diagnostics.CodeAnalysis.NotNullWhenAttribute
  • global::System.Diagnostics.CodeAnalysis.UnscopedRefAttribute
  • global::System.Diagnostics.CodeAnalysis.SetsRequiredMembersAttribute
  • global::System.Linq.Expressions.Expression<TDelegate>
  • global::System.Reflection.MemberInfo
  • global::System.Runtime.CompilerServices.AsyncMethodBuilderAttribute
  • global::System.Runtime.CompilerServices.CallerArgumentExpressionAttribute
  • global::System.Runtime.CompilerServices.CallerFilePathAttribute
  • global::System.Runtime.CompilerServices.CallerLineNumberAttribute
  • global::System.Runtime.CompilerServices.CallerMemberNameAttribute
  • global::System.Runtime.CompilerServices.CollectionBuilderAttribute
  • global::System.Runtime.CompilerServices.DefaultInterpolatedStringHandler
  • global::System.Runtime.CompilerServices.FormattableStringFactory
  • global::System.Runtime.CompilerServices.ICriticalNotifyCompletion
  • global::System.Runtime.CompilerServices.IndexerNameAttribute
  • global::System.Runtime.CompilerServices.InlineArrayAttribute
  • global::System.Runtime.CompilerServices.INotifyCompletion
  • global::System.Runtime.CompilerServices.InterpolatedStringHandlerArgumentAttribute
  • global::System.Runtime.CompilerServices.InterpolatedStringHandlerAttribute
  • global::System.Runtime.CompilerServices.ITuple
  • global::System.Runtime.CompilerServices.ModuleInitializerAttribute
  • global::System.Runtime.CompilerServices.OverloadResolutionPriorityAttribute
  • global::System.Runtime.CompilerServices.RequiredMemberAttribute
  • global::System.Runtime.CompilerServices.TaskAwaiter
  • global::System.Runtime.CompilerServices.TaskAwaiter<TResult>
  • global::System.Runtime.CompilerServices.ValueTaskAwaiter
  • global::System.Runtime.CompilerServices.ValueTaskAwaiter<TResult>
  • global::System.Runtime.CompilerServices.Unsafe
  • global::System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute
  • global::System.Threading.Lock
  • global::System.Threading.Lock.Scope
  • global::System.Threading.Monitor
  • global::System.Threading.Tasks.Task
  • global::System.Threading.Tasks.Task<TResult>

情報テキストの末尟。