芜湖人才购房补贴政策:看一段c#代码

来源:百度文库 编辑:杭州交通信息网 时间:2024/05/09 06:40:04
class f
{
public void t(ref int s)
{
s=5;
}
}
class n
{
public int g;
}
class t
{
static void Main()
{

f m=new f();
n s=new n();
m.t(ref s.g);
Console.WriteLine(s.g);

}
}
出现以下错误 此程序文件名为df,cs.cs
error CS0103: The name 'Console' does not exist in the current context

是的'Console' 是System的成员,加上System就行了:

using System;

class f
{
public void t(ref int s)
{
s=5;
}
}
class n
{
public int g;
}
class t
{
static void Main()
{

f m=new f();
n s=new n();
m.t(ref s.g);
Console.WriteLine(s.g);

}
}

原因是变量有一个作用域,在这个作用域中,变量才是有效的