Ad
Fundamentals
Numbers
Data Types
Integers

High-performance switch statement version.

Code
Diff
  • public static class Kata
    {
        public static string IsOdd(int input)
        {
            switch( input ) {
                case 0:
                case 2:
                case 18284:
                    return "Even";
                default:
                    return "Odd";
            }
        }
    }
    • public static class Kata
    • {
    • public static string IsOdd(int input)
    • {
    • if(input % 2 == 0) return "Even";
    • else return "Odd";
    • switch( input ) {
    • case 0:
    • case 2:
    • case 18284:
    • return "Even";
    • default:
    • return "Odd";
    • }
    • }
    • }
Fundamentals
Numbers
Data Types
Integers

Real men use gratuitous switch statements.

Code
Diff
  • using System.Linq;
    
    public static class Kata
    {
        public static string IsOdd(int input)
        {
            switch( input.ToString().Last() ) {
                case '0':
                case '2':
                case '4':
                case '6':
                case '8':
                    return "Even";
                default:
                    return "Odd";
            }
        }
    }
    • using System.Linq;
    • public static class Kata
    • {
    • public static string IsOdd(int input)
    • {
    • if(input % 2 == 0) return "Even";
    • else return "Odd";
    • switch( input.ToString().Last() ) {
    • case '0':
    • case '2':
    • case '4':
    • case '6':
    • case '8':
    • return "Even";
    • default:
    • return "Odd";
    • }
    • }
    • }