编译下面的代码时,我一直收到“CS1513:}预期”错误。错误发生在user_input方法的左括号中。
我是C#的新手,还在学习。对不起,如果我错过了一些明显的东西。我已经搜索了多个论坛,但没有找到解决方案。在此先感谢您的帮助!
val component = context.getComponent();
println(calculate(component));
def calculate( component: MyComponent[File] ): Unit = ???
答案 0 :(得分:4)
您应该在方法之外声明所有公共变量,因为您在每个函数中使用它们并且VS考虑这一点,而不是 OR
其 ||
强>
using System;
namespace App
{
class AppClass
{
public int input1;
public int input2;
public string operation;
public int output;
static void Main()
{
}
void user_input()
{
while (operation != "+" || operation != "-")
{
Console.WriteLine("Would you like to Add or Subtract?");
operation = Convert.ToString(Console.ReadLine());
}
Console.WriteLine("Please enter the first input:");
input1 = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Please enter the second input:");
input2 = Convert.ToInt32(Console.ReadLine());
}
void do_math()
{
if (operation == "+")
{
output = input1 + input2;
}
else
{
output = input1 - input2;
}
}
void display()
{
Console.WriteLine("The answer is {0}", output);
}
}
}