关于“外出”c#中函数参数的前缀
本文关键字:函数 参数 前缀 外出 关于 | 更新日期: 2023-09-27 18:17:47
namespace ...
{
class Class1
{
public void test(out int a){
a = 1;
return;
}
}
}
static void Main()
{
Class1 c1 = new Class1();
int a=1;
c1.Test(a);
}
编译错误:
Error 1 The best overloaded method match for 'ConsoleApplication1.func1.Class1.test(out int)' has some invalid arguments
我帮你修好了:
static void Main()
{
Class1 c1 = new Class1();
int a=1;
c1.test(out a);
}
当调用具有out
或ref
参数的函数时,您需要通过将参数标记为out
或ref
来对其给予一些尊重。
MSDN参考页
要使用out形参,方法定义和调用方法必须显式使用out关键字。
在呼叫中需要out
关键字:
c1.Test(out a);
除了名字的大写是错误的(test
和Test
)