判斷奇偶數

       //流行的"程序員"
        public static bool IsOdd(int n)
        {
            while (true)
            {
                switch (n)
                {
                    case 1: return true;
                    case 0: return false;
                }
                n -= 2;
            }
        }

        // 中規中矩的程序員 
        public static bool IsOdd(int n)
        {
            return (n % 2 == 1) ? true : false;
        }

        // 有經驗的C#程序員 
        public static bool IsOdd(int n)
        {
            return Convert.ToBoolean(n % 2);
        }

        // 彙編程序員 
        public static bool IsOdd(int n)
        {
            return Convert.ToBoolean(n & 1);
        }
相關文章
相關標籤/搜索