void Path1(bool a, bool b, bool c, bool d){ if(a){ if(b){ if(c){ if(d){ Console.WriteLine("a->b->c->d"); }else{ Console.WriteLine("a->b->c"); } }else{ Console.WriteLine("a->b"); } }else{ Console.WriteLine("a"); } }else{ Console.WriteLine(""); } } void Path2(bool a, bool b, bool c, bool d){ if(!a){ Console.WriteLine(""); return; } if(!b){ Console.WriteLine("a"); return; } if(!c){ Console.WriteLine("a->b"); return; } if(!d){ Console.WriteLine("a->b->c"); return; } Console.WriteLine("a->b->c->d"); } string PathValue(bool a, bool b, bool c, bool d){ if(!a){ return ""; } if(!b){ return "a"; } if(!c){ return "a->b"; } if(!d){ return "a->b->c"; } return "a->b->c->d"; } void Path3(bool a, bool b, bool c, bool d){ Console.WriteLine(PathValue(a,b,c,d)); } void Path(bool a, bool b, bool c, bool d){ if(a){ if(b){ if(c){ if(d){ Console.WriteLine("a->b->c"); }else{ Console.WriteLine("a->b->c->d"); } }else{ Console.WriteLine("a->b"); } }else{ Console.WriteLine("a"); } }else{ Console.WriteLine(""); } } // Path(true,true,false,false); int Calc(char op, int a, int b){ if(op=='+'){ return a+b; }else if(op=='-'){ return a-b; }else if(op=='*'){ return a*b; }else if(op=='/'){ try{ return a/b; }catch(DivideByZeroException e){ throw new Exception("被除数不能为0"); } }else{ throw new Exception("无效的操作符"); } } int ret = Calc('*', Calc('+',1, Calc('-',3,Calc('/',1,0))), Calc('-',3,Calc('/',1,2))); Console.WriteLine("ret={0}", ret);