天天看點

【轉】C#判斷奇偶數的函數

// 現代流行的"程式員"
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);
}