Базовые типы данных. Ввод и вывод. Арифметические операции. (C-Sharp): различия между версиями
Перейти к навигации
Перейти к поиску
(не показано 8 промежуточных версий этого же участника) | |||
Строка 1: | Строка 1: | ||
+ | {{TOCRight}} | ||
== Базовые типы данных == | == Базовые типы данных == | ||
+ | * [https://docs.microsoft.com/ru-ru/dotnet/csharp/language-reference/builtin-types/value-types Типы значений (справка Микрософт)] | ||
<syntaxhighlight lang="c#" line> | <syntaxhighlight lang="c#" line> | ||
int a = 5; | int a = 5; | ||
Строка 11: | Строка 13: | ||
== Ввод и вывод == | == Ввод и вывод == | ||
+ | * [https://docs.microsoft.com/ru-ru/dotnet/api/system.console.readline?view=net-5.0 Console.ReadLine для чтения из консоли (справка Микрософт)] | ||
+ | * [https://docs.microsoft.com/ru-ru/dotnet/api/system.console.writeline?view=net-5.0 Console.WriteLine для вывода в консоль (справка Микрософт)] | ||
<syntaxhighlight lang="c#" line> | <syntaxhighlight lang="c#" line> | ||
Console.WriteLine("Please, enter your age:"); | Console.WriteLine("Please, enter your age:"); | ||
Строка 16: | Строка 20: | ||
int age = Convert.ToInt32(ageString); | int age = Convert.ToInt32(ageString); | ||
Console.WriteLine("Your age = " + age); | Console.WriteLine("Your age = " + age); | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | <syntaxhighlight lang="c#" line> | ||
+ | double age = Convert.ToDouble(ageString); | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | <syntaxhighlight lang="c#" line> | ||
+ | int x = Convert.ToInt32(Console.ReadLine()); | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | <syntaxhighlight lang="c#" line> | ||
+ | var x = 1.123456; | ||
+ | Console.WriteLine(x.ToString("0.000")); | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | <syntaxhighlight lang="c#" line> | ||
+ | var s = Console.ReadLine().Split(); | ||
</syntaxhighlight> | </syntaxhighlight> | ||
== Арифметические операции == | == Арифметические операции == | ||
− | * [https://docs.microsoft.com/ru-ru/dotnet/csharp/language-reference/operators/assignment-operator Операторы присваивания] | + | * [https://docs.microsoft.com/ru-ru/dotnet/csharp/language-reference/operators/assignment-operator Операторы присваивания (справка Микрософт)] |
<syntaxhighlight lang="c#" line> | <syntaxhighlight lang="c#" line> | ||
fahrenheit = celcius*1.8 + 32; | fahrenheit = celcius*1.8 + 32; |
Текущая версия на 15:48, 19 сентября 2022
Базовые типы данных
1 int a = 5;
2 double b = a / 2;
3 bool test = true;
4 char firstLetter = 'C';
5 string name = "Hi, there!";
6 int[] age = new int[5];
7 int[] age2 = {3, 7, 15, 21, 7};
Ввод и вывод
- Console.ReadLine для чтения из консоли (справка Микрософт)
- Console.WriteLine для вывода в консоль (справка Микрософт)
1 Console.WriteLine("Please, enter your age:");
2 string ageString = Console.ReadLine();
3 int age = Convert.ToInt32(ageString);
4 Console.WriteLine("Your age = " + age);
1 double age = Convert.ToDouble(ageString);
1 int x = Convert.ToInt32(Console.ReadLine());
1 var x = 1.123456;
2 Console.WriteLine(x.ToString("0.000"));
1 var s = Console.ReadLine().Split();
Арифметические операции
1 fahrenheit = celcius*1.8 + 32;