-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path8. Conditional constructions
More file actions
54 lines (47 loc) · 982 Bytes
/
Copy path8. Conditional constructions
File metadata and controls
54 lines (47 loc) · 982 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
using System;
namespace App
{
class Program
{
static void Main(string[] args)
{
// if... else switch..case
int num1 = 8;
int num2 = 16;
if (num1 > num2 && num1 == 8)
{
Console.WriteLine("num more than num2");
}
else if (num1 < num2)
{
Console.WriteLine($"{num1} less than {num2}");
}
else
{
Console.WriteLine($"{num1} equally {num2}");
}
Console.WriteLine("Press Y or N");
string selection = Console.ReadLine();
switch(selection)
{
case "Y":
Console.WriteLine("You pressed key Y");
break;
case "N":
Console.WriteLine("You pressed key N");
break;
default:
Console.WriteLine("You pressed an unknown key");
break;
}
// Ternary operator op1?op2:op3;
int x = 3;
int y = 2;
Console.WriteLine("Press + or -");
string selection2 = Console.ReadLine();
int z = selection2 == "+" ? (x + y) : (x - y);
Console.WriteLine(z);
Console.ReadKey();
}
}
}