/
aprogrammer
/
dotnet-docs
Обзор
Документация
Войти
/
aprogrammer
/
dotnet-docs
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
docs/fundamentals/runtime-libraries/snippets/System.Globalization/NumberFormatInfo/csharp/parse1.cs
41 строка
1 KB
Genevieve Warren
Extract remarks for System.Globalization* (#38912)
29 дек 2023, 20:03
Не верифицирован
29 дек 2023, 20:03
7f945f9
Код
Авторство
О чём код?
// <Snippet4> using System; using System.Globalization; public class ParseEx1 { public static void Main() { String[] values = { "1,034,562.91", "9 532 978,07" }; String[] cultureNames = { "en-US", "fr-FR", "" }; foreach (var value in values) { foreach (var cultureName in cultureNames) { CultureInfo culture = CultureInfo.CreateSpecificCulture(cultureName); String name = culture.Name == "" ? "Invariant" : culture.Name; try { Decimal amount = Decimal.Parse(value, culture); Console.WriteLine("'{0}' --> {1} ({2})", value, amount, name); } catch (FormatException) { Console.WriteLine("'{0}': FormatException ({1})", value, name); } } Console.WriteLine(); } } } // The example displays the following output: // '1,034,562.91' --> 1034562.91 (en-US) // '1,034,562.91': FormatException (fr-FR) // '1,034,562.91' --> 1034562.91 (Invariant) // // '9 532 978,07': FormatException (en-US) // '9 532 978,07' --> 9532978.07 (fr-FR) // '9 532 978,07': FormatException (Invariant) // </Snippet4>