C#

Ternary Operator in C#

ยท 1 min read

Also called One-line if:

Syntax

condition ? consequent : alternative

Example

using UnityEngine;
using System.Collections;

public class TernaryOperator: MonoBehaviour {
  void Start() {
    int age = 20;
    string message;
    message = health > 20 ? "should buy life insurance" : "Player is young";
  }
}