-
Notifications
You must be signed in to change notification settings - Fork 19
/
Operators.cs
executable file
·141 lines (120 loc) · 3.64 KB
/
Operators.cs
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
//Rextester.Program.Main is the entry point for your code. Don't change it.
//Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
namespace Rextester
{
public class Program
{
public static void Main(string[] args)
{
//What are operators?
//operators are characters that allow for certain actions or
//operations to take place
//Equals =
//assignment
int myInt = 10;
//comparing values ==
if(myInt == 10)
{
Console.WriteLine("Im 10");
}
//not equals !=
if(myInt != 8)
{
Console.WriteLine("Im not 8");
}
//+
myInt = myInt + 2;
Console.WriteLine(myInt);
//-
myInt = myInt - 2;
Console.WriteLine(myInt);
//*
myInt = myInt * 2;
Console.WriteLine(myInt);
// /
myInt = myInt / 2;
Console.WriteLine(myInt);
//pre-incremention ++ --
int i = 0;
Console.WriteLine(++i); //should print 1
//post-incrementations
Console.WriteLine(i++); //should still print 1
Console.WriteLine(i); //should print 2
// > < greater than and less than
int A = 10;
int B = 15;
if(A > B)
{
Console.WriteLine("A is bigger");
}
else
{
Console.WriteLine("B is Bigger");
}
//>= <= greater than or equal to or less than and equal to
B = 5;
if(A >= B)
{
Console.WriteLine("A is bigger");
}
else
{
Console.WriteLine("B is Bigger");
}
// +=, -=, *=, /=
int c = 10;
c +=2; //prints 12
c -=2; //prints 10
c *=2; //prints 20
c /=2; //prints 10
//Modulo %
//remainder
int D = 21;
int E = D % 5;
Console.WriteLine(E);
//?:
int NewInt = 0;
// recipient = condition ? true : false;
NewInt = (E > 3) ? NewInt = 5 : NewInt = 2;
Console.WriteLine(NewInt);
//what are logical operators?
//these allow for logical operations to take place. These are
// AND, OR, and NOT
// && , ||, !
bool boolA = true;
bool boolB = false;
//&&
if( boolA && boolB)
{
Console.WriteLine("YAY!");
}
else
{
Console.WriteLine("OH NO!");
}
// ||
if( boolA || boolB)
{
Console.WriteLine("YAY!");
}
else
{
Console.WriteLine("OH NO!");
}
//!
if( boolA && !boolB) //if boolA is true AND boolB is false
{
Console.WriteLine("YAY!");
}
else
{
Console.WriteLine("OH NO!");
}
//HOW to make comments //
}
}
}