0Pricing
C# Academy · Lesson

Operators & expressions: arithmetic, comparison, logical

Work with arithmetic operators (+, -, *, /, %), comparisons (==, !=, , =), and logical operators (&&, ||, !). Understand precedence and short-circuiting.

Operator map

Goal: Use arithmetic, comparison, and logical operators to build clear expressions.

  • Math with + - * / %
  • Compare values
  • Combine checks with && and ||

Arithmetic basics

Arithmetic: / with ints truncates; use doubles for fractional results.

using System;

public class Program
{
  public static void Main(string[] args)
  {
    int a = 9;
    int b = 4;
    Console.WriteLine("a + b = " + (a + b));
    Console.WriteLine("a - b = " + (a - b));
    Console.WriteLine("a * b = " + (a * b));
    Console.WriteLine("a / b = " + (a / b)); // integer division
    Console.WriteLine("a % b = " + (a % b)); // remainder
  }
}

All lessons in this course

  1. Value vs reference; literals; var inference; const/readonly
  2. Operators & expressions: arithmetic, comparison, logical
  3. Suffixes in practice; casting vs conversion; C# 6 object creation
← Back to C# Academy