int scalar = creature is SpecialCreature ? (creature.IsAwesome ? 700 : 500) : (creature is NotSoNormalCreature ?
(creature.IsAwesome ? (creature is IGreatCreature ? 450 : 280) : 240) :
(creature.IsAwesome ? (creature is IGreatCreature ? 300 : 200) : 160));
我该如何编写代码以使其更具可读性?C#代码可读性问题
我以为只是建立IFS的,但后来我想到了做某种“ConditionFactory”怎么样?这是否有意义,还是这样简单的任务太复杂了?
int scalar;
if (creature is SpecialCreature)
{
scalar = creature.IsAwesome ? 700 : 500;
}
else if (creature is NotSoNormalCreature)
{
if (creature.IsAwesome)
{
scalar = creature is IGreatCreature ? 450 : 280;
}
else
{
scalar = 240;
}
}
else
{
if (creature.IsAwesome)
{
scalar = creature is IGreatCreature ? 300 : 200;
}
else
{
scalar = 160;
}
}
让我看看等价的if-then语法 - 这会让我的眼睛受伤... – IAbstract 2011-05-29 00:50:28
这些标量值在应用程序执行期间是否改变,或者它们对于每种生物类型都是永久的? – twk 2011-05-29 00:54:19
当生物为SpecialCreature并且IGreatCreature或不IGreatCreature时,它计数相同。 – twk 2011-05-29 01:01:41