Created
March 22, 2012 03:56
-
-
Save cbcwebdev/2155703 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Calculator | |
{ | |
public static int Add(IEnumerable<int> operands) | |
{ | |
return operands.Sum(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class CalculatorApp | |
{ | |
public void Start(string prompt) | |
{ | |
do { | |
try { | |
Console.WriteLine(prompt); | |
var operands = GetInput(); | |
Console.WriteLine(Calculator.Add(operands)); | |
} | |
catch(Exception ex) { Console.WriteLine(ex); } | |
} while(true); | |
} | |
private IEnumerable<int> GetInput() | |
{ | |
var input = Console.ReadLine(); | |
return input.Split(' ').Cast<int>(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void Main() | |
{ | |
var calculator = new CalculatorApp(); | |
calculator.Start("Type in some numbers for me to add!"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment