當前位置: 首頁>>代碼示例>>C#>>正文


C# Parse.splitString方法代碼示例

本文整理匯總了C#中SimpleCalculator.Parse.splitString方法的典型用法代碼示例。如果您正苦於以下問題:C# Parse.splitString方法的具體用法?C# Parse.splitString怎麽用?C# Parse.splitString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在SimpleCalculator.Parse的用法示例。


在下文中一共展示了Parse.splitString方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: ParseEnsureICanSplitTheFormattedStringWithAMethod

 public void ParseEnsureICanSplitTheFormattedStringWithAMethod()
 {
     Parse test = new Parse();
     string input = "-20 / -30";
     test.splitString(input);
     Assert.AreEqual(-20, test.FirstNumber);
     Assert.AreEqual(-30, test.SecondNumber);
     Assert.AreEqual("/", test.Operator);
 }
開發者ID:wfhutch,項目名稱:simpleCalculatorJuniper,代碼行數:9,代碼來源:ParseTests.cs

示例2: EvaluateEnsureProperSubtractionOperation

 public void EvaluateEnsureProperSubtractionOperation()
 {
     Parse test = new Parse();
     Evaluate subtractTest = new Evaluate();
     string input = "-2345 - -567";
     test.splitString(input);
     decimal actual = subtractTest.calculate(test.FirstNumber, test.Operator, test.SecondNumber);
     int expected = -1778;
     Assert.AreEqual(expected, actual);
 }
開發者ID:wfhutch,項目名稱:simpleCalculatorJuniper,代碼行數:10,代碼來源:EvaluateTests.cs

示例3: EvaluateEnsureProperMultiplicationOperation

 public void EvaluateEnsureProperMultiplicationOperation()
 {
     Parse test = new Parse();
     Evaluate multiplyTest = new Evaluate();
     string input = "-10 * 2";
     test.splitString(input);
     decimal actual = multiplyTest.calculate(test.FirstNumber, test.Operator, test.SecondNumber);
     int expected = -20;
     Assert.AreEqual(expected, actual);
 }
開發者ID:wfhutch,項目名稱:simpleCalculatorJuniper,代碼行數:10,代碼來源:EvaluateTests.cs

示例4: EvaluateEnsureProperModuloOperation

 public void EvaluateEnsureProperModuloOperation()
 {
     Parse test = new Parse();
     Evaluate moduloTest = new Evaluate();
     string input = "24 % 5";
     test.splitString(input);
     decimal actual = moduloTest.calculate(test.FirstNumber, test.Operator, test.SecondNumber);
     int expected = 4;
     Assert.AreEqual(expected, actual);
 }
開發者ID:wfhutch,項目名稱:simpleCalculatorJuniper,代碼行數:10,代碼來源:EvaluateTests.cs

示例5: EvaluateEnsureProperDivisionOperation

 public void EvaluateEnsureProperDivisionOperation()
 {
     Parse test = new Parse();
     Evaluate divideTest = new Evaluate();
     string input = "5 / 2";
     test.splitString(input);
     decimal actual = divideTest.calculate(test.FirstNumber, test.Operator, test.SecondNumber);
     decimal expected = 2.50M;
     Assert.AreEqual(expected, actual);
 }
開發者ID:wfhutch,項目名稱:simpleCalculatorJuniper,代碼行數:10,代碼來源:EvaluateTests.cs

示例6: Main

        static void Main(string[] args)
        {
            Parse userInput = new Parse();
            Evaluate expression = new Evaluate();
            Stack stack = new Stack();

            bool runProgram = true;
            int counter = 0;

            while (runProgram)
            {
                Console.Write("[" + counter + "]> ");

                string response = Console.ReadLine();

                if (response == "exit" || response == "quit")
                {
                    Console.WriteLine("Bye!! \nPress any key to close program...");
                    runProgram = false;
                    Console.ReadKey();
                }
                else if(response == "lastq")
                {
                    Console.WriteLine("     " + stack.LastExpression);
                }
                else if (response == "last")
                {
                    Console.WriteLine("     " + stack.LastAnswer);

                }
                else
                {
                    string splitResponse = userInput.formatInput(response);
                    if (splitResponse == "Invalid Expression. Please try again!")
                    {
                        Console.WriteLine(splitResponse);
                    }
                    else
                    {
                        userInput.splitString(splitResponse);
                        decimal user_answer =
                            expression.calculate(userInput.FirstNumber, userInput.Operator, userInput.SecondNumber);
                        counter += 1;
                        Console.WriteLine("   " + "=" + " " + user_answer);
                        stack.LastExpression = response;
                        stack.LastAnswer = user_answer;
                    }
                }
            }
        }
開發者ID:wfhutch,項目名稱:simpleCalculatorJuniper,代碼行數:50,代碼來源:Program.cs


注:本文中的SimpleCalculator.Parse.splitString方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。