Anteckning
Åtkomst till den här sidan kräver auktorisering. Du kan prova att logga in eller ändra kataloger.
Åtkomst till den här sidan kräver auktorisering. Du kan prova att ändra kataloger.
C.1 Allmänt
En förenlig C#-implementering ska tillhandahålla en minsta uppsättning typer med specifika semantik. Dessa typer och deras medlemmar visas här, i alfabetisk ordning efter namnområde och typ. En formell definition av de typer och deras medlemmar som identifieras i (§C.2) finns i ISO/IEC 23271:2012 Common Language Infrastructure (CLI), Partition IV; Base Class Library (BCL), Extended Numerics Library och Extended Array Library, som ingår i referensen i den här specifikationen. För en lista över typer och deras medlemmar som krävs utöver de som anges i §C.2, se §C.3.
Obs! Införandet av en delmängd av CLI:s biblioteks-API skapar inte något beroende av själva CLI; en efterlevnadsimplementering behöver inte byggas på eller riktas mot CLI.
Den här texten är informativ.
Standardbiblioteket är avsett att vara den minsta uppsättning typer och medlemmar som krävs av en C#-implementering. Därför innehåller den endast de medlemmar som uttryckligen krävs av C#-språkspecifikationen.
En C#-implementering som följer förväntas tillhandahålla ett betydligt mer omfattande bibliotek som gör det möjligt att skriva användbara program. En implementering som överensstämmer kan till exempel utöka det här biblioteket med
- Lägga till namnområden.
- Lägga till typer.
- Lägga till medlemmar i icke-gränssnittstyper.
- Lägga till mellanliggande basklasser eller gränssnitt.
- Att ha struct- och klasstyper implementerar ytterligare gränssnitt.
- Lägga till attribut (förutom ConditionalAttribute) till befintliga typer och medlemmar.
Slut på informativ text.
C.2 Standardbibliotekstyper som definierats i ISO/IEC 23271
Obs! Vissa
structtyper nedan harreadonlymodifieraren. Den här modifieraren var inte tillgänglig när ISO/IEC 23271 släpptes, men krävs för att följa implementeringarna av den här specifikationen. slutkommentar
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 sealed Exception? InnerException { get; }
        public virtual string Message { get; }
    }
    public class GC { }
    public interface IDisposable
    {
        void Dispose();
    }
    public interface IEquatable<T>
    {
        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>
    {
        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);
    }
    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>();
    }
}
namespace System.Threading
{
    public static class Monitor
    {
        public static void Enter(object obj);
        public static void Exit(object obj);
    }
}
C.3 Standardbibliotekstyper som inte definierats i ISO/IEC 23271
Följande typer, inklusive de medlemmar som förtecknas, ska definieras i ett standardbibliotek som uppfyller kraven. (Dessa typer kan definieras i en framtida version av ISO/IEC 23271.) Det förväntas att många av dessa typer kommer att ha fler medlemmar tillgängliga än vad som anges.
En implementering som överensstämmer kan tillhandahålla Task.GetAwaiter() och Task<TResult>.GetAwaiter() som tilläggsmetoder.
namespace System
{
    public interface IAsyncDisposable
    {
        ValueTask DisposeAsync();
    }
    public class FormattableString : IFormattable { }
    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<Index>
    {
        /// <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);
    }
    public interface IAsyncDisposable
    {
        public System.Threading.Tasks.ValueTask DisposeAsync();
    }
}
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
    {
        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.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) {}
    }
}
namespace System.Linq.Expressions
{
    public sealed class Expression<TDelegate>
    {
        public TDelegate Compile();
    }
}
namespace System.Runtime.CompilerServices
{
    [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | 
        AttributeTargets.Interface, 
        Inherited = false, AllowMultiple = false)]
    public sealed class AsyncMethodBuilderAttribute : Attribute
    {
        public AsyncMethodBuilderAttribute(Type builderType) {}
 
        public Type BuilderType { get; }
    }
    [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);
    }
    public interface INotifyCompletion
    {
        void OnCompleted(Action continuation);
    }
    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();
    }
    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; }
    }
}
namespace System.Threading.Tasks
{
    public class Task
    {
        public System.Runtime.CompilerServices.TaskAwaiter GetAwaiter();
    }
    public class Task<TResult> : Task
    {
        public new System.Runtime.CompilerServices.TaskAwaiter<T> 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-formatspecifikationer
Innebörden av formaten, som används i interpolerade stränguttryck (§12.8.3), definieras i ISO/IEC 23271:2012. För enkelhetens skull kopieras följande text från beskrivningen av System.IFormattable.
Den här texten är informativ.
Ett format är en sträng som beskriver utseendet på ett objekt när det konverteras till en sträng. Antingen standardformat eller anpassade format kan användas. Ett standardformat har formatet Axx, där A är ett enda alfabetiskt tecken som kallas formatspecificerare, och xx är ett heltal mellan noll och 99 inklusive, kallat precisionsspecificerare. Formatspecificeraren styr vilken typ av formatering som tillämpas på det värde som representeras som en sträng. Precisionsspecificeraren styr antalet signifikanta siffror eller decimaler i strängen, om tillämpligt.
Obs! En lista över standardformatsspecificerare finns i tabellen nedan. Observera att en viss datatyp, till exempel
System.Int32, kanske inte stöder en eller flera av standardformatsspecificerarna. slutkommentar
Obs! När ett format innehåller symboler som varierar beroende på kultur, till exempel valutasymbolen som ingår i formaten "C" och "c", tillhandahåller ett formateringsobjekt de faktiska tecken som används i strängrepresentationen. En metod kan innehålla en parameter för att skicka ett
System.IFormatProviderobjekt som tillhandahåller ett formateringsobjekt, eller så kan metoden använda standardformateringsobjektet, som innehåller symboldefinitionerna för den aktuella kulturen. Den aktuella kulturen använder vanligtvis samma uppsättning symboler som används i hela systemet som standard. I basklassbiblioteket är formateringsobjektet för systemspecifika numeriska typer enSystem.Globalization.NumberFormatInfoinstans. TillSystem.DateTimeexempel används enSystem.Globalization.DateTimeFormatInfo. slutkommentar
I följande tabell beskrivs standardformatsspecificerare och associerade formateringsobjektmedlemmar som används med numeriska datatyper i basklassbiblioteket.
| Formatera specificerare | beskrivning | 
|---|---|
| 
 
 | 
              Valutaformat: Används för strängar som innehåller ett monetärt värde. Medlemmarna  
               Om precisionsspecificeraren utelämnas  | 
| 
 
 | 
              Decimalformat: (Det här formatet är endast giltigt när det anges med integraldatatyper.) Används för strängar som innehåller heltalsvärden. Negativa tal prefixeras med den negativa talsymbolen som anges av egenskapen  Precisionsspecificeraren avgör det minsta antalet siffror som visas i strängen. Om den angivna precisionen kräver fler siffror än värdet innehåller, är strängen vänster vadderad med nollor. Om precisionsspecificeraren anger färre siffror än vad som finns i värdet ignoreras precisionsspecificeraren. | 
| 
 
 | Vetenskapligt (tekniskt) format: Används för strängar i något av följande formulär: [-]m.ddddddDE+xxx [-]m.ddddddDE-xxx [-]m.dddddde+xxx [-]m.ddddddde-xxx Den negativa talsymbolen ('-') visas endast om värdet är negativt och tillhandahålls av egenskapen  Exakt en decimal (m) som inte är noll föregår decimaltecknet ('.'), som tillhandahålls av  Precisionsspecificeraren avgör antalet decimaler (dddddd) i strängen. Om precisionsspecificeraren utelämnas inkluderas sex decimaler i strängen. Exponenten (+/-xxx) består av antingen en positiv eller negativ talsymbol följt av minst tre siffror (xxx). Exponenten är vänster vadderad med nollor, om det behövs. Fallet med formatspecificeraren ("E" eller "e") avgör det skiftläge som används för exponentprefixet (E eller e) i strängen. Resultaten avrundas till närmaste representerande värde vid behov. Symbolen för positivt tal tillhandahålls av egenskapen  | 
| 
 
 | Fast punktformat: Används för strängar i följande formulär: [-]m.dd... d Minst en decimal (m) som inte är noll föregår decimaltecknet ('.'), som tillhandahålls av  Ett symboltecken för negativt tal ('-') föregår endast m om värdet är negativt. Den här symbolen tillhandahålls av egenskapen  Precisionsspecificeraren avgör antalet decimaler (dd... d) i strängen. Om precisionsspecificeraren utelämnas  | 
| 
 
 | Allmänt format: Strängen är formaterad i antingen fast punktformat ("F" eller "f") eller vetenskapligt format ("E" eller "e"). För integraltyper: Värden formateras med fast punktformat om exponentprecisionsspecificerare< , där exponenten är exponenten för värdet i vetenskapligt format. För alla andra värden används vetenskapligt format. Om precisionsspecificeraren utelämnas används en standardprecision som är lika med den fältbredd som krävs för att visa det maximala värdet för datatypen, vilket resulterar i att värdet formateras i fast punktformat. Standardprecisionerna för integraltyper är följande: 
                        
               
                        
               
                        
               För typerna Enkel, Decimal och Dubbel: Värden formateras med fast punktformat om exponenten ≥ -4 och exponentprecisionsspecificeraren, där < är exponenten för värdet i vetenskapligt format. För alla andra värden används vetenskapligt format. Resultaten avrundas till närmaste representerande värde vid behov. Om precisionsspecificeraren utelämnas används följande standardprecisioner: 
                        
               
                        
               
                        
               För alla typer: 
 | 
| 
 
 | Talformat: Används för strängar i följande formulär: [-]d,ddd,ddd.dd... d Representationen av negativa värden bestäms av  Minst en decimal (d) som inte är noll föregår decimaltecknet ('.'), som tillhandahålls av  Precisionsspecificeraren avgör antalet decimaler (dd... d). Om precisionsspecificeraren utelämnas  | 
| 
 
 | 
              Procentformat: Används för strängar som innehåller en procentandel. Medlemmarna  
               Om ingen precision anges bestäms antalet decimaler i resultatet av  Resultatet skalas med 100 (,99 blir 99 %). | 
| 
 
 | Tur och retur-format: (Det här formatet är endast giltigt när det anges med System.DoubleellerSystem.Single.) Används för att säkerställa att precisionen i strängrepresentationen av ett flyttalsvärde är sådan att parsning av strängen inte resulterar i en förlust av precision jämfört med det ursprungliga värdet. Om den maximala precisionen för datatypen (7 förSystem.Singleoch 15 förSystem.Double) skulle leda till en förlust av precision ökas precisionen med två decimaler. Om en precisionsspecificerare levereras med den här formatspecificeraren ignoreras den. Det här formatet är annars identiskt med fast punktformatet. | 
| 
 
 | Hexadecimalt format: (Det här formatet är endast giltigt när det anges med integraldatatyper.) Används för strängrepresentationer av tal i bas 16. Precisionen avgör det minsta antalet siffror i strängen. Om precisionen anger fler siffror än talet innehåller, är talet vänsterfyllt med nollor. Fallet med formatspecificeraren ("X" eller "x") avgör om versaler eller gemener används i hexadecimal representation. | 
Om det numeriska värdet är ett System.Single eller System.Double med värdet NaN, PositiveInfinityeller NegativeInfinity, ignoreras formatspecificeraren och något av följande returneras: System.Globalization.NumberFormatInfo.NaNSymbol, System.Globalization.NumberFormatInfo.PositiveInfinitySymboleller System.Globalization.NumberFormatInfo.NegativeInfinitySymbol.
Ett anpassat format är en sträng som anges som ett format som inte är i form av en standardformatsträng (Axx) som beskrivs ovan. I följande tabell beskrivs de tecken som används för att skapa anpassade format.
| Formatera specificerare | beskrivning | 
|---|---|
| 0(noll) | Nollplatshållare: Om värdet som formateras har en siffra i den position där ett "0" visas i anpassat format kopieras den siffran till utdatasträngen. Annars lagras en nolla i den positionen i utdatasträngen. Positionen för det vänstra hörnet "0" före decimaltecknet och det högra "0" efter decimaltecknet avgör det intervall med siffror som alltid finns i utdatasträngen. Antalet platshållare för noll och/eller siffror efter decimaltecknet avgör antalet siffror som visas efter decimaltecknet. Värden avrundas efter behov. | 
| # | Platshållare för siffror: Om värdet som formateras har en siffra i den position där ett #visas i anpassat format kopieras den siffran till utdatasträngen. Annars lagras ingenting i den positionen i utdatasträngen. Observera att den här specificeraren aldrig lagrar 0-tecknet om det inte är en betydande siffra, även om "0" är den enda siffran i strängen. (Tecknet "0" visas i utdatasträngen om det är en betydande siffra.) Antalet platshållare för noll och/eller siffror efter decimaltecknet avgör antalet siffror som visas efter decimaltecknet. Värden avrundas efter behov. | 
| .(period) | Decimalavgränsare: Vänster mest '.'
tecken i formatsträngen bestämmer platsen för decimalavgränsaren i det formaterade värdet. ytterligare '.' tecken ignoreras. Egenskapen System.Globalization.NumberFormatInfo.NumberDecimalSeparatorbestämmer den symbol som används som decimalavgränsare. | 
| ,(kommatecken) | 
              Gruppavgränsare och talskalning: Tecknet "" har två syften. Om det anpassade formatet först innehåller det här tecknet mellan två noll- eller sifferplatshållare (0 eller #) och till vänster om decimaltecknet om det finns en, kommer utdata att ha gruppavgränsare infogade mellan varje grupp med siffror till vänster om decimalavgränsaren. Egenskaperna  Om formatsträngen innehåller ett eller flera tecken direkt till vänster om decimaltecknet skalas talet. Skalningsfaktorn bestäms av antalet gruppavgränsningstecken omedelbart till vänster om decimaltecknet. Om det finns x tecken divideras värdet med 1 000X innan det formateras. Formatsträngen "0" delar till exempel upp ett värde med en miljon. Observera att förekomsten av tecknet för att indikera skalning inte infogar gruppavgränsare i utdatasträngen. Om du vill skala ett tal med 1 miljon och infoga gruppavgränsare använder du därför ett anpassat format som liknar '#,##0,'. | 
| %(procent) | Platshållare i procent: Förekomsten av ett %-tecken i ett anpassat format gör att ett tal multipliceras med 100 innan det formateras. Procentsymbolen infogas i utdatasträngen på den plats där %visas i formatsträngen. Egenskapen System.Globalization.NumberFormatInfo.PercentSymbolbestämmer procentsymbolen. | 
| 
 
 
 
 
 
 | Teknikformat: Om någon av strängarna "E", "E+", "E-", "e", "e", "e+" eller "e-" finns i ett anpassat format och följs omedelbart av minst ett 0-tecken formateras värdet med vetenskaplig notation. Antalet "0" tecken efter exponentprefixet (E eller e) avgör det minsta antalet siffror i exponenten. Formaten "E+" och "e+" anger att en positiv eller negativ talsymbol alltid föregår exponenten. Formaten "E", "E-", "e" eller "e-" anger att en negativ talsymbol föregår negativa exponenter. ingen symbol föregås av positiva exponenter. Symbolen för positivt tal tillhandahålls av egenskapen System.Globalization.NumberFormatInfo.PositiveSign. Den negativa talsymbolen tillhandahålls av egenskapenSystem.Globalization.NumberFormatInfo.NegativeSign. | 
| \(omvänt snedstreck) | Escape-tecken: På vissa språk, till exempel C#, gör omvänt snedstreck att nästa tecken i anpassat format tolkas som en escape-sekvens. Den används med formateringssekvenser för C-språk, till exempel \n (ny rad). På vissa språk måste själva escape-tecknet föregås av ett escape-tecken när det används som en literal. Annars tolkar en kompilator tecknet som en flyktsekvens. Det här escape-tecknet måste inte stödjas på alla programmeringsspråk. | 
| 
 
 | Strängliteral: Tecken som omges av enkla eller dubbla citattecken kopieras bokstavligen till utdatasträngen och påverkar inte formateringen. | 
| ;(semikolon) | Avsnittsavgränsare: Tecknet ';' används för att avgränsa avsnitt för positiva, negativa och noll tal i formatsträngen. (Den här funktionen beskrivs i detalj nedan.) | 
| Övrigt | Alla andra tecken: Alla andra tecken lagras i utdatasträngen som literaler i den position där de visas. | 
Observera att för formatsträngar med fast punkt (strängar som inte innehåller "E0", "E+0", "E-0", "e0", "e0", "e+0" eller "e-0") avrundas talen till så många decimaler som det finns platshållare för noll eller siffror till höger om decimaltecknet. Om det anpassade formatet inte innehåller någon decimalavgränsare avrundas talet till närmaste heltal. Om talet har fler siffror än det finns platshållare för noll eller siffror till vänster om decimaltecknet kopieras de extra siffrorna till utdatasträngen omedelbart före den första noll- eller sifferplatshållaren.
Ett anpassat format kan innehålla upp till tre avsnitt avgränsade med avsnittsavgränsningstecken för att ange olika formatering för positiva, negativa och nollvärden. Avsnitten tolkas på följande sätt:
- Ett avsnitt: Det anpassade formatet gäller för alla värden (positiva, negativa och noll). Negativa värden innehåller ett negativt tecken. 
- Två avsnitt: Det första avsnittet gäller positiva värden och nollor, och det andra avsnittet gäller negativa värden. Om värdet som ska formateras är negativt, men blir noll efter avrundning enligt formatet i det andra avsnittet, formateras den resulterande nollpunkten enligt det första avsnittet. Negativa värden innehåller inte ett negativt tecken för att ge fullständig kontroll över representationer av negativa värden. Ett negativt kan till exempel representeras i parenteser med ett anpassat format som liknar '####.#####; (####.####)’. 
- Tre avsnitt: Det första avsnittet gäller positiva värden, det andra avsnittet gäller negativa värden och det tredje avsnittet gäller nollor. Det andra avsnittet kan vara tomt (ingenting visas mellan semikolonen), i vilket fall det första avsnittet gäller för alla icke-nollvärden och negativa värden innehåller ett negativt tecken. Om talet som ska formateras inte är noll, men blir noll efter avrundning enligt formatet i det första eller andra avsnittet, formateras den resulterande nollan enligt det tredje avsnittet. 
Typerna System.Enum och System.DateTime stöder även formatspecificerare för att formatera strängrepresentationer av värden. Innebörden av en specifik formatspecificerare varierar beroende på vilken typ av data (numeriskt, datum/tid, uppräkning) som formateras. Se System.Enum och System.Globalization.DateTimeFormatInfo för en omfattande lista över de formatspecificerare som stöds av varje typ.
Förkortningar för C.5-bibliotekstyp
Följande bibliotekstyper refereras till i den här specifikationen. De fullständiga namnen på dessa typer, inklusive den globala namnområdeskvalificeraren, visas nedan. I den här specifikationen visas dessa typer som antingen det fullständigt kvalificerade namnet; med den globala namnområdeskvalificeraren utelämnad; eller som ett enkelt namn av okvalificerad typ, där även namnområdet utelämnas. Till exempel betyder typen ICollection<T>, när den används i den här specifikationen, alltid typen 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.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.NotNullAttribute
- global::System.Diagnostics.CodeAnalysis.NotNullIfNotNullAttribute
- global::System.Diagnostics.CodeAnalysis.NotNullWhenAttribute
- global::System.Linq.Expressions.Expression<TDelegate>
- global::System.Reflection.MemberInfo
- global::System.Runtime.CompilerServices.AsyncMethodBuilderAttribute
- global::System.Runtime.CompilerServices.CallerFileAttribute
- global::System.Runtime.CompilerServices.CallerLineNumberAttribute
- global::System.Runtime.CompilerServices.CallerMemberNameAttribute
- global::System.Runtime.CompilerServices.FormattableStringFactory
- global::System.Runtime.CompilerServices.ICriticalNotifyCompletion
- global::System.Runtime.CompilerServices.IndexerNameAttribute
- global::System.Runtime.CompilerServices.INotifyCompletion
- global::System.Runtime.CompilerServices.TaskAwaiter
- global::System.Runtime.CompilerServices.TaskAwaiter<T>
- global::System.Runtime.CompilerServices.ValueTaskAwaiter
- global::System.Runtime.CompilerServices.ValueTaskAwaiter<TResult>
- global::System.Runtime.CompilerServices.Unsafe
- global::System.Threading.Monitor
- global::System.Threading.Tasks.Task
- global::System.Threading.Tasks.Task<TResult>
Slut på informativ text.
ECMA C# draft specification