передать значение по ссылке в конструкторе, сохранить его, а затем изменить позже, как?

Как мне реализовать эту функциональность? Я думаю, что это не работает, потому что я сохраняю его в конструкторе? Нужно ли мне делать какие-то тряпки Box / Unbox?

    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;
        }

    }
7
задан Ryan Lee 5 July 2011 в 05:31
поделиться