BasicKnowledgeCSharp/LessonsAndTasks/Lesson 5 - Конвертация строки, класс Convert/Lesson 5 - конвертация строки, класс Convert/Program.cs

66 lines
1.4 KiB
C#
Raw Normal View History

2025-05-12 02:48:54 +03:00
/*
* Author: Nikolay Dvurechensky
* Site: https://www.dvurechensky.pro/
* Gmail: dvurechenskysoft@gmail.com
* Last Updated: 12 мая 2025 02:47:11
* Version: 1.0.3
*/
using System;
2024-10-05 09:59:53 +03:00
using System.Globalization;
/*
* конвертация строки
* класс Convert
*/
class Program
{
static void Main()
{
string str = "5";
string str2 = "2";
string str3 = "1,3";
string str4 = "1.5";
var numberFormatInfo = new NumberFormatInfo()
{
NumberDecimalSeparator = ".",
};
double db = Convert.ToDouble(str3);
double db1 = Convert.ToDouble(str4, numberFormatInfo);
Console.WriteLine(db);
Console.WriteLine(db1);
Console.WriteLine(str + str2);
int a = Convert.ToInt32(str); // Демонстрация Convert
Console.WriteLine(a);
Console.WriteLine("\t");
string str1;
int a1 = 0, a2 = 0, result;
Console.WriteLine("Введите первое число: ");
str1 = Console.ReadLine();
if(!string.IsNullOrWhiteSpace(str1))
a1 = Convert.ToInt32(str1);
Console.WriteLine("Введите второе число: ");
str1 = Console.ReadLine();
if (!string.IsNullOrWhiteSpace(str1))
a2 = Convert.ToInt32(str1);
result = a1 + a2;
Console.WriteLine("Сумма чисел: " + result);
}
}