本文整理匯總了C#中SimpleCalculator.Parse.setOperatorIndex方法的典型用法代碼示例。如果您正苦於以下問題:C# Parse.setOperatorIndex方法的具體用法?C# Parse.setOperatorIndex怎麽用?C# Parse.setOperatorIndex使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類SimpleCalculator.Parse
的用法示例。
在下文中一共展示了Parse.setOperatorIndex方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: Main
static void Main(string[] args)
{
int count = 0;
Constant currentConstant = new Constant();
Evaluate expression;
while (true)
{
Console.Write("[{0}]> ", count);
string input = Console.ReadLine();
expression = new Evaluate(input, currentConstant);
if (input.ToLower() == "exit" || input.ToLower() == "quit")
{
break;
}
else if (input.IndexOf("=")> -1)
{
//set variable
Parse addConstant = new Parse(input, currentConstant);
addConstant.setOperatorIndex();
currentConstant.addConst(addConstant.StringFirst(), addConstant.secondNum());
// = saved 'x' as '3'
Console.WriteLine("= saved '" + addConstant.StringFirst() + "' as '" + addConstant.secondNum() + "'");
}
else
{
int answer = expression.doMath();
Console.WriteLine(" = {0}", answer);
count++;
}
}
}
示例2: ParseOnlyAllowsSimpleExpressions
public void ParseOnlyAllowsSimpleExpressions()
{
Parse twoPlusThree = new Parse("2 - 5 + 3");
twoPlusThree.setOperatorIndex();
twoPlusThree.firstNum();
twoPlusThree.secondNum();
}
示例3: ParseOnlyAllowsNumbersSecond
public void ParseOnlyAllowsNumbersSecond()
{
Parse twoPlusThree = new Parse("2 + b");
twoPlusThree.setOperatorIndex();
twoPlusThree.firstNum();
twoPlusThree.secondNum();
}
示例4: ParseCanFindSecondNum
public void ParseCanFindSecondNum()
{
Parse twoPlusThree = new Parse("2 + 3");
twoPlusThree.setOperatorIndex();
twoPlusThree.firstNum();
Assert.AreEqual(3, twoPlusThree.secondNum());
}
示例5: ParseAllowsConstantsFirst
public void ParseAllowsConstantsFirst()
{
Constant newConstant = new Constant();
Parse aplus3 = new Parse("a + 3", newConstant);
aplus3.addConst("a", 5);
aplus3.setOperatorIndex();
Assert.AreEqual(5, aplus3.firstNum());
}
示例6: ParseCanFindOperation
public void ParseCanFindOperation()
{
Parse twoPlusThree = new Parse("2 + 3");
twoPlusThree.setOperatorIndex();
Assert.AreEqual("+", twoPlusThree.mathOperation());
}