How to save a ref variable for later use?

前端 未结 4 700
忘掉有多难
忘掉有多难 2020-12-18 20:15

So this works..

public MyClass(ref Apple apple)
{
    apple = new Apple(\"Macintosh\"); // Works fine
}

But is it possible to do something

4条回答
  •  梦毁少年i
    2020-12-18 20:37

    Why not just have ModifyApple return the modified Apple instance?

    public Apple ModifyApple()
    {
        myApple = new Apple("Macintosh"); // does not change the input variable like the first example did
        return myApple;
    }
    

提交回复
热议问题