/
aprogrammer
/
dotnet-docs
Обзор
Документация
Войти
/
aprogrammer
/
dotnet-docs
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
docs/fundamentals/runtime-libraries/snippets/System.Globalization/NumberFormatInfo/csharp/customize_ssn1.cs
37 строк
1 KB
Genevieve Warren
Extract remarks for System.Globalization* (#38912)
29 дек 2023, 20:03
Не верифицирован
29 дек 2023, 20:03
7f945f9
Код
Авторство
О чём код?
// <Snippet2> using System; using System.Globalization; public class CustomizeSSNEx { public static void Main() { // Instantiate a read-only NumberFormatInfo object. CultureInfo enUS = CultureInfo.CreateSpecificCulture("en-US"); NumberFormatInfo nfi = enUS.NumberFormat; // Modify the relevant properties. nfi.NumberGroupSeparator = "-"; nfi.NumberGroupSizes = new int[] { 3, 2, 4 }; nfi.NumberDecimalDigits = 0; int[] ids = { 111223333, 999776666 }; // Produce the result string by calling ToString. foreach (var id in ids) Console.WriteLine(id.ToString("N", enUS)); Console.WriteLine(); // Produce the result string using composite formatting. foreach (var id in ids) Console.WriteLine(String.Format(enUS, "{0:N}", id)); } } // The example displays the following output: // 1112-23-333 // 9997-76-666 // // 1112-23-333 // 9997-76-666 // </Snippet2>