# Ternary Operator

A single line if/else statement.

## What is the **ternary operator**?

A single line if/else statement.

```csharp
double chocolate = 2.50;
double donuts = 3.99;

double maxPrice = (chocolate > donuts) ? chocolate : donuts;
```

Level: Apprentice · [More C# terms at this level](https://www.ask-codey.com/glossary/subjects/c-sharp/apprentice)

Updated: October 15, 2026

## In other subjects

- [Ternary Operator in Java](https://www.ask-codey.com/glossary/ternary-operator)
- [Ternary Operator in Java](https://www.ask-codey.com/glossary/ternary-operator-java)
- [Ternary Operator in JavaScript](https://www.ask-codey.com/glossary/ternary-operator-javascript-2)

Source: https://www.ask-codey.com/glossary/ternary-operator-c-style
