
+, -, *, /, %
++, --
using System;
namespace IncDecOperator
{
class MainApp
{
static void Main(string[] args)
{
int a = 10;
Console.WriteLine(a);
Console.WriteLine(a++); // 출력 후 증가
Console.WriteLine(a);
Console.WriteLine(++a); // 증가 후 출력
}
}
}
[실행 결과]
10
10
11
12
<, >, <=, >=, ==, !=
조건식 ? 참일 때 값 : 거짓일 때 값
using System;
namespace ConditionalOperator
{
class MainApp
{
static void Main(string[] args)
{
string result = (10 % 2) == 0 ? "짝수" : "홀수";
Console.WriteLine(result);
}
}
}
[실행 결과]
짝수
&& (AND), || (OR), ! (NOT)
=, ==, -=, *=, /=, %=, &=, |=, |=, ^=, <<=, >>=
using System;
namespace AssignmentOperator
{
class MainApp
{
static void Main(string[] args)
{
int a = 100;
Console.WriteLine($"a += 90: {a += 90}");
Console.WriteLine($"a /= 10: {a /= 10}");
Console.WriteLine($"a %= 2: {a %= 2}");
Console.WriteLine($"a <<= 1: {a <<= 1}");
Console.WriteLine($"a |= 1: {a |= 1}"); // 0010 | 0001 → 0011
}
}
}
[실행 결과]
a += 90: 190
a /= 10: 19
a %= 2: 1
a <<= 1: 2
a |= 1: 3
▪ 사진 출처: Pixabay - Robert Owen-Wahl