带索引++的三元运算符给出 "Only assignment, call, increment, decrement, await and new object expressions can be used as statement"

Ternary operator with index++ gives "Only assignment, call, increment, decrement, await and new object expressions can be used as statement"

我没有得到此提示文本以及代码无法编译的原因:

int index = 0;
bool result = false;

result ? index++ : index--;

这是 increment/decrement 不是吗?

为什么会报编译错误:"Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement"?

三元运算符本身不是一个语句。里面有什么并不重要,重要的是它本身是什么。这将是一个声明:

index += result ? 1 : -1;