/
merdan
/
controlWorks_tests
Обзор
Документация
Войти
/
merdan
/
controlWorks_tests
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
Methods/TryParse.cs
40 строк
825 B
merdan
I wrote the tests
15 ноя 2025, 04:36
15 ноя 2025, 04:36
7047a79
Код
Авторство
О чём код?
namespace Methods; public class TryParse { public static bool IsParse(string str, out int number) { if (str == null) { throw new ArgumentNullException(nameof(str), "String cannot be null"); } if (str.Length == 0) { throw new ArgumentException("String cannot be empty", nameof(str)); } number = 0; int count = 0; int i = 0; if (str[0] == '-') { i++; count++; } for (i = 0; i < str.Length; i++) { if (Char.IsDigit(str[i])) { count++; } } if (count == str.Length) { number = int.Parse(str); return true; } else return false; } }