题目概述:
使用C#实现一个加减乘除的计算器。
编程:
namespace ConsoleApp1
{
class Program
{
static string[] ary = new string[] { "+", "-", "*", "/" };
private static int A(string inputStr, ref int calcType)//输入:字符串 输出:运算符在该字符串的位置和该运算符(calcType)
{
int index = -1;
for (int i = 0; i < ary.Length; i++)
{
string tag = ary[i];
index = inputStr.IndexOf(tag);//查找tag在字符串中的位置
if (index != -1)
{
calcType = i;
break;
}
}
return index;
}
private static void CalcResult(string inputStr, int calcType, int index)
{
string numStr1 = inputStr.Substring(0, index);//下标为0,开始的长度为index的子字符串
int strlen = inputStr.Count();
string numStr2 = inputStr.Substring(index