Skip to content

Commit 3d136a4

Browse files
authored
fix non-working sample (#4765)
1 parent 98aa9ec commit 3d136a4

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

samples/snippets/csharp/VS_Snippets_CLR_System/system.globalization.numberformatinfo.class/cs/parsepersisted.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ public class Example
99
{
1010
public static void Main()
1111
{
12-
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-US");
12+
CultureInfo.CurrentCulture = CultureInfo.CreateSpecificCulture("en-US");
1313
PersistData();
1414

15-
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-GB");
15+
CultureInfo.CurrentCulture = CultureInfo.CreateSpecificCulture("pt-BR");
1616
RestoreData();
1717
}
1818

samples/snippets/visualbasic/VS_Snippets_CLR_System/system.globalization.numberformatinfo.class/vb/parsepersisted.vb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ Imports System.Threading
99

1010
Module Example
1111
Public Sub Main()
12-
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-US")
12+
CultureInfo.CurrentCulture = CultureInfo.CreateSpecificCulture("en-US")
1313
PersistData()
1414

15-
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-GB")
15+
CultureInfo.CurrentCulture = CultureInfo.CreateSpecificCulture("pt-BR")
1616
RestoreData()
1717
End Sub
1818

xml/System.Globalization/NumberFormatInfo.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,9 @@
333333
### Serializing and deserializing numeric data
334334
When numeric data is serialized in string format and later deserialized and parsed, the strings should be generated and parsed by using the conventions of the invariant culture. The formatting and parsing operations should never reflect the conventions of a specific culture. If culture-specific settings are used, the portability of the data is strictly limited; it can be successfully deserialized only on a thread whose culture-specific settings are identical to those of the thread on which it was serialized. In some cases, this means that the data cannot even be successfully deserialized on the same system on which it was serialized.
335335
336-
The following example illustrates what can happen when this principle is violated. Floating-point values in an array are converted to strings when the current thread uses the culture-specific settings of the en-US culture. The data is then parsed by a thread that uses the culture-specific settings of the en-GB culture. In this case, although each parsing operation succeeds, the data does not round-trip successfully and data corruption occurs. In other cases, a parsing operation could fail and a <xref:System.FormatException> exception could be thrown.
336+
The following example illustrates what can happen when this principle is violated. Floating-point values in an array are converted to strings when the current thread uses the culture-specific settings of the en-US culture.
337+
The data is then parsed by a thread that uses the culture-specific settings of the pt-BR culture. In this case, although each parsing operation succeeds, the data doesn't round-trip successfully and data corruption occurs.
338+
In other cases, a parsing operation could fail and a <xref:System.FormatException> exception could be thrown.
337339
338340
:::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.globalization.numberformatinfo.class/cs/parsepersisted.cs" interactive="try-dotnet" id="Snippet6":::
339341
:::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.globalization.numberformatinfo.class/vb/parsepersisted.vb" id="Snippet6":::

0 commit comments

Comments
 (0)