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