我是这里的 C# 初学者,我从文本框中获取字符串并应用以下算法,但是操作数和运算符的中断不起作用..
string cal = "225+699";
char[] all= cal.ToCharArray();
int i=0,j=0;
while (all[i] != '+' || all[i] != '-' || all[i] != '/' || all[i] != 'x')
{
j++;
} // first operator check
char op = all[j + 1]; // operator save
char[] part1 = new char[j];
for (i = 0; i <= j; i++)
{
part1[i] = all[i];
}
string inp = Convert.ToString(part1);
float a = float.Parse(inp); // first operand
int l=cal.Length-(j+1);
char[] part2 = new char[l];
int c = 0;
for (i = j + 1; i <= cal.Length; i++)// starts after operator
{
part2[c] = all[i];
c++;
}
string h = Convert.ToString(part2);
float b = float.Parse(h); // other operand