When you sort operators, make sure to provide custom IComparer
void Main()
{
var comparer = new OperatorComparer();
var operators = new[] { '+', '-', '*', '/' };
Array.Sort(operators,comparer);
}
public class OperatorComparer : IComparer
{
public int Compare(object x, object y)
{
var xv = (char)x;
var yv = (char)y;
if (xv == '*' || xv == '/')
{
if(yv == '*' || yv == '/')
return 0;
else
return -1;
}
else if (yv == '+' || yv == '-')
return 0;
return 1;
}
}
THis will help, but without seeing all of your code I still assume it cannot handle parenthesies. Look into AST building parsers, they will help to create real calculator functions.