# Ternary Operator

*noun*

say it: **“TER-nuh-ree OP-er-ay-ter”** **/ˈtɜːrnəri ˈɒpəreɪtər/**

The ?: operator, which picks one of two values depending on a condition, in a single expression.

## 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;
```

## In a sentence

- “I used the **ternary operator**: string label = wins > losses ? "Winning" : "Losing";”

Level: Apprentice · [More C# terms at this level](https://www.ask-codey.com/glossary?category=c-sharp&level=2)

Updated: November 9, 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
