Nota
L'accesso a questa pagina richiede l'autorizzazione. È possibile provare ad accedere o modificare le directory.
L'accesso a questa pagina richiede l'autorizzazione. È possibile provare a modificare le directory.
La precisione massima durante la formattazione dei numeri come stringhe che usano ToString e TryFormat è stata modificata da Int32.MaxValue a 999.999.999. La precisione massima è stata precedentemente modificataInt32.MaxValue in .NET 6.
Inoltre, l'esponente massimo consentito durante l'analisi di un BigInteger da una stringa è stato limitato a 999.999.999.
Comportamento precedente
In .NET 6 la logica di analisi del formato numerico standard era limitata a una precisione pari Int32.MaxValue o inferiore. Il comportamento previsto era quello di generare un oggetto FormatException per qualsiasi precisione maggiore di Int32.MaxValue. Tuttavia, a causa di un bug, .NET 6 non ha generato tale eccezione per alcuni input di questo tipo. Il comportamento previsto era:
double d = 123.0;
d.ToString("E" + int.MaxValue.ToString()); // Doesn't throw.
long intMaxPlus1 = (long)int.MaxValue + 1;
string intMaxPlus1String = intMaxPlus1.ToString();
Assert.Throws<FormatException>(() => d.ToString("E" + intMaxPlus1String)); // Throws.
Inoltre, non esiste alcun limite per le dimensioni dell'esponente durante l'analisi di un BigInteger oggetto da una stringa.
Nuovo comportamento
A partire da .NET 7, .NET supporta la precisione fino a 999.999.999. Un'FormatException eccezione viene generata se la precisione è maggiore di 999.999.999. Questa modifica è stata implementata nella logica di analisi che influisce su tutti i tipi numerici.
double d = 123.0;
Assert.Throws<FormatException>(() => d.ToString("E" + int.MaxValue.ToString())); // Throws.
long intMaxPlus1 = (long)int.MaxValue + 1;
string intMaxPlus1String = intMaxPlus1.ToString();
Assert.Throws<FormatException>(() => d.ToString("E" + intMaxPlus1String)); // Throws.
d.ToString("E999999999"); // Doesn't throw.
d.ToString("E00000999999999"); // Doesn't throw.
Inoltre, se si tenta di analizzare sintatticamente un BigInteger con un esponente maggiore di 999.999.999 da una stringa, viene lanciata un'eccezione FormatException.
Versione introdotta
.NET 7
Tipo di cambiamento che interrompe la compatibilità
Questa modifica può influire sulla compatibilità binaria.
Motivo della modifica
Il comportamento introdotto in .NET 6 è stato progettato per generare un oggetto FormatException per una precisione maggiore di Int32.MaxValue. Tuttavia, a causa di un bug, non è stata generata tale eccezione per alcuni input superiori al massimo. Questa modifica corregge il bug limitando la precisione a 999.999.999.
Azione consigliata
Nella maggior parte dei casi, non è necessaria alcuna azione, perché è improbabile che si stia già usando una precisione superiore a 999.999.999 nelle stringhe di formato.
Le API interessate
Questa modifica è stata implementata nella logica di analisi che influisce su tutti i tipi numerici.
- System.Numerics.BigInteger.ToString(String)
- System.Numerics.BigInteger.ToString(String, IFormatProvider)
- System.Numerics.BigInteger.TryFormat(Span<Char>, Int32, ReadOnlySpan<Char>, IFormatProvider)
- System.Int32.ToString(String)
- System.Int32.ToString(String, IFormatProvider)
- System.Int32.TryFormat(Span<Char>, Int32, ReadOnlySpan<Char>, IFormatProvider)
- System.UInt32.ToString(String)
- System.UInt32.ToString(String, IFormatProvider)
- System.UInt32.TryFormat(Span<Char>, Int32, ReadOnlySpan<Char>, IFormatProvider)
- System.Byte.ToString(String)
- System.Byte.ToString(String, IFormatProvider)
- System.Byte.TryFormat(Span<Char>, Int32, ReadOnlySpan<Char>, IFormatProvider)
- System.SByte.ToString(String)
- System.SByte.ToString(String, IFormatProvider)
- System.SByte.TryFormat(Span<Char>, Int32, ReadOnlySpan<Char>, IFormatProvider)
- System.Int16.ToString(String)
- System.Int16.ToString(String, IFormatProvider)
- System.Int16.TryFormat(Span<Char>, Int32, ReadOnlySpan<Char>, IFormatProvider)
- System.UInt16.ToString(String)
- System.UInt16.ToString(String, IFormatProvider)
- System.UInt16.TryFormat(Span<Char>, Int32, ReadOnlySpan<Char>, IFormatProvider)
- System.Numerics.BigInteger.Parse
- System.Numerics.BigInteger.TryParse
- System.Int64.ToString(String)
- System.Int64.ToString(String, IFormatProvider)
- System.Int64.TryFormat(Span<Char>, Int32, ReadOnlySpan<Char>, IFormatProvider)
- System.UInt64.ToString(String)
- System.UInt64.ToString(String, IFormatProvider)
- System.UInt64.TryFormat(Span<Char>, Int32, ReadOnlySpan<Char>, IFormatProvider)
- System.Half.ToString(String)
- System.Half.ToString(String, IFormatProvider)
- System.Half.TryFormat(Span<Char>, Int32, ReadOnlySpan<Char>, IFormatProvider)
- System.Single.ToString(String)
- System.Single.ToString(String, IFormatProvider)
- System.Single.TryFormat(Span<Char>, Int32, ReadOnlySpan<Char>, IFormatProvider)
- System.Double.ToString(String)
- System.Double.ToString(String, IFormatProvider)
- System.Double.TryFormat(Span<Char>, Int32, ReadOnlySpan<Char>, IFormatProvider)
- System.Decimal.ToString(String)
- System.Decimal.ToString(String, IFormatProvider)
- System.Decimal.TryFormat(Span<Char>, Int32, ReadOnlySpan<Char>, IFormatProvider)