【发布时间】:2011-09-28 12:40:00
【问题描述】:
如何实现此功能?我认为它不起作用,因为我将它保存在构造函数中? 我需要做一些 Box/Unbox jiberish 吗?
static void Main(string[] args)
{
int currentInt = 1;
//Should be 1
Console.WriteLine(currentInt);
//is 1
TestClass tc = new TestClass(ref currentInt);
//should be 1
Console.WriteLine(currentInt);
//is 1
tc.modInt();
//should be 2
Console.WriteLine(currentInt);
//is 1 :(
}
public class TestClass
{
public int testInt;
public TestClass(ref int testInt)
{
this.testInt = testInt;
}
public void modInt()
{
testInt = 2;
}
}
【问题讨论】:
标签: c# parameters reference int