去掉if

修改前
namespace CleanCSharp.Methods.Dirty
{
    class BooleanSwitchingArgumentsExample
    {
        public void CallingCode()
        {
            if (DateTime.Now.Hour < 12)
            {
                OutputGreeting(true);
            }
            else
            {
                OutputGreeting(false);
            }
        }
        public void OutputGreeting(bool isMorning)
        {
            if (isMorning)
            {
                Console.WriteLine("Good Morning");
            }
            else
            {
                Console.WriteLine("Good Day");
            }
        }
    }
}

//修改后
namespace
CleanCSharp.Methods.Clean { class BooleanSwitchingArgumentsExample { public void CallingCode() { if (DateTime.Now.Hour < 12) { OutputMorningGreeting(); } else { OutputDaytimeGreeting(); } } private static void OutputDaytimeGreeting() { Console.WriteLine("Good Day"); } private static void OutputMorningGreeting() { Console.WriteLine("Good Morning"); } } }
原文地址:https://www.cnblogs.com/gaocong/p/6688533.html