码迷,mamicode.com
首页 > Windows程序 > 详细

【转】C#判断奇偶数的函数

时间:2016-12-21 09:57:17      阅读:198      评论:0      收藏:0      [点我收藏+]

标签:public   经验   奇偶数   判断   div   int   流行   pre   ret   

// 现代流行的"程序员"
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);
} 

 

【转】C#判断奇偶数的函数

标签:public   经验   奇偶数   判断   div   int   流行   pre   ret   

原文地址:http://www.cnblogs.com/dayang12525/p/6206339.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!