/
aprogrammer
/
dotnet-docs
Обзор
Документация
Войти
/
aprogrammer
/
dotnet-docs
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
docs/fundamentals/runtime-libraries/snippets/System/Boolean/Overview/csharp/parse3.cs
29 строк
792 B
Genevieve Warren
Add remarks for core types (#38970)
05 янв 2024, 22:14
Не верифицирован
05 янв 2024, 22:14
71d1377
Код
Авторство
О чём код?
// <Snippet9> using System; public class Example8 { public static void Main() { String[] values = { "09", "12.6", "0", "-13 " }; foreach (var value in values) { bool success, result; int number; success = Int32.TryParse(value, out number); if (success) { // The method throws no exceptions. result = Convert.ToBoolean(number); Console.WriteLine("Converted '{0}' to {1}", value, result); } else { Console.WriteLine("Unable to convert '{0}'", value); } } } } // The example displays the following output: // Converted '09' to True // Unable to convert '12.6' // Converted '0' to False // Converted '-13 ' to True // </Snippet9>