Базовые типы данных. Ввод и вывод. Арифметические операции. (C-Sharp): различия между версиями

Материал из Информационная безопасностя
Перейти к навигации Перейти к поиску
 
(не показаны 2 промежуточные версии этого же участника)
Строка 20: Строка 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>
  
 
<syntaxhighlight lang="c#" line>
 
<syntaxhighlight lang="c#" line>
 
int x = Convert.ToInt32(Console.ReadLine());
 
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>
  

Текущая версия на 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};

Ввод и вывод

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;

Задачник