将Stack传递给方法的正确方法是什么?我收到一个错误,说我的方法调用有一些无效的参数.
string userInput = inputText.Text;
Stack<double> numbers= new Stack<double>();
Stack<char> operators = new Stack<char>();
bool output;
output = calculateExpression(userInput, Stack<double> numbers, Stack<char> operators);
Run Code Online (Sandbox Code Playgroud)
我的定义:
double calculateExpression(string userInput, Stack<double> numbers, Stack<char> operators)
{}
Run Code Online (Sandbox Code Playgroud)
您不需要函数调用中的类型:
output = calculateExpression(userInput, numbers, operators);
Run Code Online (Sandbox Code Playgroud)
我还注意到你的函数返回一个double,但你将它分配给bool.您可以通过更改输出var类型来解决此问题,如:
double output;
Run Code Online (Sandbox Code Playgroud)
和
double calculateExpression(string userInput, Stack<double> numbers, Stack<char> operators)
{}
Run Code Online (Sandbox Code Playgroud)
或者通过更改函数返回值,如:
bool calculateExpression(string userInput, Stack<double> numbers, Stack<char> operators)
{}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
60 次 |
| 最近记录: |