Returning a reference to an object
<p>I'm trying to return a reference to an object, not pass it by value. This is due to not being able to pass a property by reference. </p>

<p>How can I get the code below to write 'new number plate' not 'old number plate'. After a bit of looking it seems like I cant. Just wanted to be sure first. Seems odd you cant. </p>

<p>Cheers</p>

<p>Steve</p>

<p><a href="http://hardcode.ro/archive/2008/03/18/c-return-reference-types.aspx" rel="nofollow">http://hardcode.ro/archive/2008/03/18/c-return-reference-types.aspx</a> </p>

<p><a href="http://geekswithblogs.net/akraus1/archive/2006/02/10/69047.aspx" rel="nofollow">http://geekswithblogs.net/akraus1/archive/2006/02/10/69047.aspx</a></p>

<pre><code> public partial class Test2 : DefaultPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            var car = new Car();
            var numberPlate = car.GetNumberPlate();
            numberPlate = "new number plate";
            Response.Write(car.GetNumberPlate());
        }
    }
}


public class Car
{
    private string _numberPlate;

    public Car()
    {
        _numberPlate="old number plate";

    }

    public string NumberPlate
    {
        get { return _numberPlate; }
        set { _numberPlate = value;}
    }
    public string GetNumberPlate()
    {
        return _numberPlate;
    }
}
</code></pre>
