无法在 C# 中调用函数

通用游戏开发

我试图调用这个计算器功能:

public static void Main(string[] args) {
    int answer = calculate(int a, int b);
    Console.WriteLine(answer);
}

public int calculate(int a, int b) {
    return a + b;
}

但我不断收到有关进行非静态引用的错误

橡子时间

不能调用函数的原因是不能从静态函数调用非静态函数,请尝试将 static 关键字添加到计算函数头

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章