Search code examples
c#ternary

In which version of C# was the ternary operator introduced?


I have searched the most obvious sources but can't find the ternary operator listed as being introduced in a specific version. (I need to know this information for a historical reference).


Solution

  • It was introduced at the beginning, in C# 1.

    If you want an authoritative source, the Wikipedia page has links to the specifications. The ECMA Spec for C# 1.0, 1.1 and 1.2 says:

    14.12 Conditional operator

    The ?: operator is called the conditional operator. It is at times also called the ternary operator.

    conditional-expression:
        conditional-or-expression
        conditional-or-expression   ?   expression   :   expression 
    

    ... and so on.