← C# tutorial

C#

Operators

Arithmetic (+ - * /), comparison (== != > <), and logical (&& || !) operators work as in most C-family languages.

Example: a boolean expression, interpolated into output

using System;

class Program {
    static void Main() {
        int score = 85;
        bool passed = score >= 50 && score <= 100;
        Console.WriteLine($"Passed: {passed}");
    }
}
Passed: True

Notice the capital True in the output, unlike C++ or Java, C# actually prints its boolean values as the words True/False directly, no ternary trick needed. The $"..." syntax is a C# string interpolation, letting {passed} be evaluated and inserted directly, the same underlying idea as Python's f-strings or JavaScript's template literals, just C#'s particular spelling of it.

Example
using System;

class Program {
    static void Main() {
        int score = 85;
        bool passed = score >= 50 && score <= 100;
        Console.WriteLine($"Passed: {passed}");
    }
}
Output
Passed: True
Ready to go further?

These free tutorials are a preview of what a Code Secure Academy cohort covers, project work and all.

Explore our tracks

Cookie preferences

Choose what you're comfortable with. You can change this any time from the footer.

Don't miss out

Ready to build something real?

Create a free account to enroll in a track, and get notified the moment a cohort opens.

Create free account