C-Sharp: различия между версиями
Перейти к навигации
Перейти к поиску
(не показано 6 промежуточных версий этого же участника) | |||
Строка 1: | Строка 1: | ||
+ | {{TOCRight}} | ||
+ | |||
+ | == IDE == | ||
+ | * [https://visualstudio.microsoft.com/vs/community/ Visual Studio Community] | ||
+ | * [https://www.jetbrains.com/rider/ JetBrains Rider] | ||
+ | |||
+ | == C# - 101 == | ||
+ | * [https://channel9.msdn.com/Series/CSharp-101 Channel9 MSDN] | ||
+ | |||
== Hello World == | == Hello World == | ||
− | * [[Hello | + | * [[Hello - C-Sharp]] |
== Объявление переменных == | == Объявление переменных == | ||
Строка 10: | Строка 19: | ||
bool test = true; | bool test = true; | ||
char firstLetter = 'C'; | char firstLetter = 'C'; | ||
− | int[] age = new int[5] | + | string name = "Hi, there!"; |
+ | int[] age = new int[5]; | ||
int[] age2 = {3, 7, 15, 21, 7}; | int[] age2 = {3, 7, 15, 21, 7}; | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | == Ввод и вывод == | ||
+ | <syntaxhighlight lang="c#" line> | ||
+ | Console.WriteLine("Please, enter your age:"); | ||
+ | string ageString = Console.ReadLine(); | ||
+ | int age = Convert.ToInt32(ageString); | ||
+ | Console.WriteLine("Your age = " + age); | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | == Условный оператор == | ||
+ | <syntaxhighlight lang="c#" line> | ||
+ | Console.WriteLine("Please, enter your age:"); | ||
+ | string ageString = Console.ReadLine(); | ||
+ | int age = Convert.ToInt32(ageString); | ||
+ | if (age > 65) | ||
+ | { | ||
+ | Console.WriteLine("Here is your pension."); | ||
+ | } | ||
+ | else | ||
+ | { | ||
+ | Console.WriteLine("Good morning people!"); | ||
+ | } | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | == Циклы == | ||
+ | <syntaxhighlight lang="c#" line> | ||
+ | Console.WriteLine("while loop"); | ||
+ | i = 1; | ||
+ | while (i < 11) | ||
+ | { | ||
+ | Console.WriteLine(i); | ||
+ | i++; | ||
+ | } | ||
+ | |||
+ | Console.WriteLine("do while loop"); | ||
+ | i = 1; | ||
+ | do | ||
+ | { | ||
+ | Console.WriteLine(i); | ||
+ | i++; | ||
+ | } while (i < 11); | ||
+ | |||
+ | Console.WriteLine("for loop"); | ||
+ | for (int j = 1; j < 11; j++) | ||
+ | { | ||
+ | Console.WriteLine(j); | ||
+ | } | ||
</syntaxhighlight> | </syntaxhighlight> |
Текущая версия на 12:13, 30 марта 2021
IDE
C# - 101
Hello World
Объявление переменных
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 Console.WriteLine("Please, enter your age:");
2 string ageString = Console.ReadLine();
3 int age = Convert.ToInt32(ageString);
4 if (age > 65)
5 {
6 Console.WriteLine("Here is your pension.");
7 }
8 else
9 {
10 Console.WriteLine("Good morning people!");
11 }
Циклы
1 Console.WriteLine("while loop");
2 i = 1;
3 while (i < 11)
4 {
5 Console.WriteLine(i);
6 i++;
7 }
8
9 Console.WriteLine("do while loop");
10 i = 1;
11 do
12 {
13 Console.WriteLine(i);
14 i++;
15 } while (i < 11);
16
17 Console.WriteLine("for loop");
18 for (int j = 1; j < 11; j++)
19 {
20 Console.WriteLine(j);
21 }