【发布时间】:2011-01-28 11:07:26
【问题描述】:
只是出于好奇,问这个
像下面的表达式一样
a = (condition) ? x : y; // two outputs
为什么我们不能有一个枚举运算符?
说,
myValue = f ??? fnApple() : fnMango() : fnOrange(); // no. of outputs specified in the enum definition
而不是 switch 语句(即使重构是可能的)
enum Fruit
{
apple,
mango,
orange
};
Fruit f = Fruit.apple;
还是某种无用的算子?
【问题讨论】:
-
除了混淆之外,我没有看到这一点。 (基于布尔表达式选择结果出现了很多,但不是枚举。)
标签: c# enums operators ternary-operator